IndexRepositoryImpl extends AbstractCRUDRepository<Index> implements IndexRepository { @Override public List<Index> readAllCached(Identifier id) { String key = id.getDatabaseName() + ":" + id.getTableName(); Cache c = CacheFactory.getCache("index"); Element e = c.get(key); if (e == null || e.getObjectValue() == null) { List<Index> all = readAll(id); if (all != null && !all.isEmpty()) { e = new Element(key, all); c.put(e); } else { return all; } } else { if (logger.isTraceEnabled()) { logger.trace("Pulling Index from Cache: " + e.getObjectValue().toString()); } } return (List<Index>) e.getObjectValue(); } IndexRepositoryImpl(Session session); @Override boolean exists(Identifier identifier); @Override Index read(Identifier identifier); @Override Index create(Index entity); @Override void markActive(Index entity); @Override Index update(Index entity); @Override void delete(Identifier id); @Override void delete(Index entity); @Override List<Index> readAll(Identifier id); @Override List<Index> readAll(); @Override List<Index> readAllCached(Identifier id); @Override long countAll(Identifier id);  }
@Test public void testReadAllCached() { System.out.println("readAllCached"); Index testIndex = Fixtures.createTestIndexOneField(); Index testIndex2 = Fixtures.createTestIndexTwoField(); f.insertIndex(testIndex); f.insertIndex(testIndex2); String database = testIndex.getDatabaseName(); String table = testIndex.getTableName(); IndexRepository instance = new IndexRepositoryImpl(f.getSession()); List<Index> result = instance.readAllCached(new Identifier(database, table)); assertEquals(2, result.size()); assertEquals(result.get(0), testIndex); assertEquals(result.get(1), testIndex2); }