MATIH Platform is in active MVP development. Documentation reflects current implementation status.
9. Query Engine & SQL
Caching
Overview

Caching Architecture

The Query Engine implements a sophisticated multi-level caching system designed to minimize redundant computation while maintaining data freshness. The cache architecture combines in-memory speed with distributed durability and semantic intelligence to maximize cache hit rates.


Cache Layers

  Query Request
       |
       v
  +----+----+
  | Semantic |--- Template match ---> Return cached result
  | Cache    |
  +----+----+
       |
       v
  +----+----+
  |  L1     |--- In-memory hit ---> Return (sub-millisecond)
  | Caffeine|
  +----+----+
       |
       v
  +----+----+
  |  L2     |--- Redis hit -------> Promote to L1 + Return
  |  Redis  |
  +----+----+
       |
       v
  Execute Query ---> Cache result in L1 + L2
LayerTechnologyCapacityTTLLatencyPurpose
SemanticIn-memory indexUnlimited templatesSame as L2sub-msMatch structurally similar queries
L1Caffeine256 MB / 1000 entries10 minutessub-msHot query results for the local JVM
L2RedisConfigurable1 hour1-5msShared cache across Query Engine replicas

Key Components

ComponentSource FileRole
MultiLevelCacheServicecache/MultiLevelCacheService.javaL1 + L2 cache operations
SemanticCacheServicecache/SemanticCacheService.javaTemplate normalization and matching
AdaptiveCachePolicycache/AdaptiveCachePolicy.javaPer-table freshness policies
CacheWarmingServicecache/CacheWarmingService.javaProactive cache population
CacheAnalyticsServicecache/CacheAnalyticsService.javaHit rate analytics and dashboards
CacheInvalidationServicecache/CacheInvalidationService.javaProgrammatic invalidation
CacheInvalidationListenercache/CacheInvalidationListener.javaEvent-driven invalidation
CacheConfigcache/CacheConfig.javaConfiguration properties

Subsections

PageDescription
Multi-Level CacheL1 in-memory (Caffeine) + L2 distributed (Redis) with GZIP compression
Semantic CacheTemplate normalization, parameter extraction, fuzzy matching
Adaptive PoliciesPer-table freshness requirements, staleness tracking
Cache WarmingProactive population of popular queries
Cache AnalyticsHit rates, efficiency reports, heatmaps, time-series
InvalidationQuery, dependency, tenant, and schema-based invalidation
ConfigurationComplete cache configuration reference