Class HTM::QueryCache ¶
| Inherits | Object |
| Defined in | lib/htm/query_cache.rb |
Thread-safe query result cache with TTL and statistics
Provides LRU caching for expensive query results with: * Configurable size and TTL * Thread-safe statistics tracking * Fast cache key generation (using Ruby's built-in hash) * Selective cache invalidation by method type
@example Create a cache
@example Use the cache
@example Check statistics
@example Selective invalidation
Constants¶
METHOD_PREFIX ¶
Cache key prefix for method-based invalidation
Attributes¶
enabled [R] ¶
Returns the value of attribute enabled.
Public Instance Methods¶
clear!() ¶
Clear all cached entries
- @return [void]
enabled?() ¶
Check if cache is enabled
- @return [Boolean]
fetch(method) ¶
Fetch a value from cache or execute block
- @param method [Symbol] Method name for cache key
- @param args [Array] Arguments for cache key
- @return [Object] Cached or computed value
- @yield Block that computes the value if not cached
initialize(size: 1000, ttl: 300) ¶
Initialize a new query cache
- @param size [Integer] Maximum number of entries (default: 1000, use 0 to disable)
- @param ttl [Integer] Time-to-live in seconds (default: 300)
- @return [QueryCache] a new instance of QueryCache
invalidate!() ¶
Invalidate cache (alias for clear!)
- @return [void]
invalidate_methods!(*methods) ¶
Invalidate cache entries for specific methods only
More efficient than full invalidation when only certain types of cached data
need to be refreshed.
- @param methods [Array@return [Integer] Number of entries invalidated
stats() ¶
Get cache statistics
- @return [Hash, nil] Statistics hash or nil if disabled