Class QueryExecutionCache

java.lang.Object
com.loomcache.server.query.QueryExecutionCache

public class QueryExecutionCache extends Object
Caches query results for identical queries within a TTL window. Invalidates entries when underlying maps are modified.
  • Constructor Details

    • QueryExecutionCache

      public QueryExecutionCache(long ttlMs, int maxCacheSize)
      Creates a new QueryExecutionCache with configurable TTL and max size.
      Parameters:
      ttlMs - time-to-live in milliseconds (default 5000)
      maxCacheSize - maximum entries to cache (default 500)
    • QueryExecutionCache

      public QueryExecutionCache()
      Creates a QueryExecutionCache with default settings (5000ms TTL, 500 entries).
  • Method Details

    • getIfPresent

      public @Nullable List<SqlRow> getIfPresent(String sql)
      Returns a cached result if available and not expired, or null.
      Parameters:
      sql - the SQL query
      Returns:
      cached result rows, or null if not found or expired
    • cache

      public void cache(String sql, List<SqlRow> result)
      Caches a query result.
      Parameters:
      sql - the SQL query
      result - the result rows to cache
    • invalidateForMap

      public void invalidateForMap(String mapName)
      Invalidates cache entries for a specific map name.
      Parameters:
      mapName - the map that was modified
    • clear

      public void clear()
      Clears all cached results.
    • getStats

      public QueryExecutionCache.CacheStats getStats()
      Returns cache performance statistics.
      Returns:
      CacheStats with hit rate and size