@Test public void testTtl() { SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0); CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO"); Cachable result = Mockito.mock(Cachable.class); assertNull(cache.computeTtl(id, result, null)); assertEquals(Long.valueOf(1), cache.computeTtl(id, result, 1L)); AccessInfo ai = new AccessInfo(); Mockito.stub(result.getAccessInfo()).toReturn(ai); Table t = new Table(); t.setProperty(DataModifiable.DATA_TTL, "2"); ai.addAccessedObject(t); assertEquals(Long.valueOf(2), cache.computeTtl(id, result, null)); Table t1 = new Table(); Schema s = new Schema(); t1.setParent(s); s.setProperty(DataModifiable.DATA_TTL, "0"); ai.addAccessedObject(t1); assertEquals(Long.valueOf(0), cache.computeTtl(id, result, null)); }
Long computeTtl(CacheID id, T t, Long ttl) { if (!(t instanceof Cachable) || type != Type.RESULTSET) { return ttl; } Cachable c = (Cachable)t; AccessInfo info = c.getAccessInfo(); if (info == null) { return ttl; } Set<Object> objects = info.getObjectsAccessed(); if (objects == null) { return ttl; } long computedTtl = Long.MAX_VALUE; for (Object o : objects) { if (!(o instanceof AbstractMetadataRecord)) { continue; } AbstractMetadataRecord amr = (AbstractMetadataRecord)o; Long l = getDataTtl(amr); if (l == null || l < 0) { continue; } if (l == 0) { if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_DQP, "Not adding cache entry", id, "since", amr.getFullName(), "has caching disabled"); } return Long.valueOf(0); } computedTtl = Math.min(l, computedTtl); } if (ttl != null) { ttl = Math.min(ttl, computedTtl); } else if (computedTtl != Long.MAX_VALUE) { ttl = computedTtl; } return ttl; }
SessionAwareCache { Long computeTtl(CacheID id, T t, Long ttl) { if (!(t instanceof Cachable) || type != Type.RESULTSET) { return ttl; } Cachable c = (Cachable)t; AccessInfo info = c.getAccessInfo(); if (info == null) { return ttl; } Set<Object> objects = info.getObjectsAccessed(); if (objects == null) { return ttl; } long computedTtl = Long.MAX_VALUE; for (Object o : objects) { if (!(o instanceof AbstractMetadataRecord)) { continue; } AbstractMetadataRecord amr = (AbstractMetadataRecord)o; Long l = getDataTtl(amr); if (l == null || l < 0) { continue; } if (l == 0) { if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_DQP, "Not adding cache entry", id, "since", amr.getFullName(), "has caching disabled"); } return Long.valueOf(0); } computedTtl = Math.min(l, computedTtl); } if (ttl != null) { ttl = Math.min(ttl, computedTtl); } else if (computedTtl != Long.MAX_VALUE) { ttl = computedTtl; } return ttl; } }
SessionAwareCache { Long computeTtl(CacheID id, T t, Long ttl) { if (!(t instanceof Cachable) || type != Type.RESULTSET) { return ttl; } Cachable c = (Cachable)t; AccessInfo info = c.getAccessInfo(); if (info == null) { return ttl; } Set<Object> objects = info.getObjectsAccessed(); if (objects == null) { return ttl; } long computedTtl = Long.MAX_VALUE; for (Object o : objects) { if (!(o instanceof AbstractMetadataRecord)) { continue; } AbstractMetadataRecord amr = (AbstractMetadataRecord)o; Long l = getDataTtl(amr); if (l == null || l < 0) { continue; } if (l == 0) { if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_DQP, "Not adding cache entry", id, "since", amr.getFullName(), "has caching disabled"); } return Long.valueOf(0); } computedTtl = Math.min(l, computedTtl); } if (ttl != null) { ttl = Math.min(ttl, computedTtl); } else if (computedTtl != Long.MAX_VALUE) { ttl = computedTtl; } return ttl; } SessionAwareCache(String cacheName, final CacheFactory cacheFactory, final Type type, int maxStaleness); }
SessionAwareCache { Long computeTtl(CacheID id, T t, Long ttl) { if (!(t instanceof Cachable) || type != Type.RESULTSET) { return ttl; } Cachable c = (Cachable)t; AccessInfo info = c.getAccessInfo(); if (info == null) { return ttl; } Set<Object> objects = info.getObjectsAccessed(); if (objects == null) { return ttl; } long computedTtl = Long.MAX_VALUE; for (Object o : objects) { if (!(o instanceof AbstractMetadataRecord)) { continue; } AbstractMetadataRecord amr = (AbstractMetadataRecord)o; Long l = getDataTtl(amr); if (l == null || l < 0) { continue; } if (l == 0) { if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_DQP, "Not adding cache entry", id, "since", amr.getFullName(), "has caching disabled"); } return Long.valueOf(0); } computedTtl = Math.min(l, computedTtl); } if (ttl != null) { ttl = Math.min(ttl, computedTtl); } else if (computedTtl != Long.MAX_VALUE) { ttl = computedTtl; } return ttl; } SessionAwareCache(String cacheName, final CacheFactory cacheFactory, final Type type, int maxStaleness); T get(CacheID id); int getCacheHitCount(); int getRequestCount(); int getCachePutCount(); int getTotalCacheEntries(); T remove(CacheID id, Determinism determinismLevel); void put(CacheID id, Determinism determinismLevel, T t, Long ttl); void clearAll(); void clearForVDB(String vdbName, String version); void clearForVDB(VDBKey vdbKey); void setTupleBufferCache(TupleBufferCache bufferManager); void setModTime(long modTime); static Collection<String> getCacheTypes(); boolean isTransactional(); double getCacheHitRatio(); CacheStatisticsMetadata buildCacheStats(String name); }
SessionAwareCache { Long computeTtl(CacheID id, T t, Long ttl) { if (!(t instanceof Cachable) || type != Type.RESULTSET) { return ttl; } Cachable c = (Cachable)t; AccessInfo info = c.getAccessInfo(); if (info == null) { return ttl; } Set<Object> objects = info.getObjectsAccessed(); if (objects == null) { return ttl; } long computedTtl = Long.MAX_VALUE; for (Object o : objects) { if (!(o instanceof AbstractMetadataRecord)) { continue; } AbstractMetadataRecord amr = (AbstractMetadataRecord)o; Long l = getDataTtl(amr); if (l == null || l < 0) { continue; } if (l == 0) { if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_DQP, "Not adding cache entry", id, "since", amr.getFullName(), "has caching disabled"); } return Long.valueOf(0); } computedTtl = Math.min(l, computedTtl); } if (ttl != null) { ttl = Math.min(ttl, computedTtl); } else if (computedTtl != Long.MAX_VALUE) { ttl = computedTtl; } return ttl; } SessionAwareCache(String cacheName, final CacheFactory cacheFactory, final Type type, int maxStaleness); T get(CacheID id); int getCacheHitCount(); int getRequestCount(); int getCachePutCount(); int getTotalCacheEntries(); T remove(CacheID id, Determinism determinismLevel); void put(CacheID id, Determinism determinismLevel, T t, Long ttl); void clearAll(); void clearForVDB(String vdbName, String version); void clearForVDB(VDBKey vdbKey); void setTupleBufferCache(TupleBufferCache bufferManager); void setModTime(long modTime); static Collection<String> getCacheTypes(); boolean isTransactional(); double getCacheHitRatio(); CacheStatisticsMetadata buildCacheStats(String name); static final String REPL; static final int DEFAULT_MAX_SIZE_TOTAL; }