Skip to main content

Persistent Cache

Overview

SmartEngine in WeSQL uses S3 as the primary storage backend. While S3 provides scalable and cost-effective storage, it introduces challenges related to latency and API call costs:

  • High Latency: Accessing data directly from S3 can lead to increased latency, negatively impacting database operation performance.
  • API Call Costs: S3 charges based on API operations, meaning frequent data access can become costly.

To address these challenges, SmartEngine incorporates a persistent cache mechanism, leveraging local SSD or EBS for faster, more cost-efficient data access.

Persistent Cache

The persistent cache is a local caching layer that stores frequently accessed data on local disks (SSD or EBS) to reduce reliance on S3. It acts as an intermediary between S3 and the database, improving performance and reducing operational costs.

  • LRU Eviction: The cache uses the Least Recently Used (LRU) eviction policy to automatically remove the least accessed data when space is needed for new entries. This ensures that the cache size is closely aligned with actual data access needs. In most cases, frequently accessed data represents only a small fraction of the total dataset. Thus, the persistent cache optimizes storage usage while improving access performance.

  • Read-Write-Through & Read-Through Modes: The persistent cache supports two modes. Choosing the right mode helps balance performance and cache storage efficiency depending on your workload.

    • Read-Write-Through (default): Data is added to the persistent cache both when it is read and when it is written.
    • Read-Through: Data is added to the persistent cache only when it is read.
  • Crash Resilience: After a system restart, the persistent cache retains its state, eliminating the need to re-cache data from S3. This ensures data is readily available upon recovery, minimizing downtime. The cache restoration process is handled asynchronously, preventing an increase in Recovery Time Objective (RTO).

  • Adjustable Size: The persistent cache size can be configured via the persistent_cache_size parameter. This flexibility allows the cache to scale according to varying business demands. If the persistent cache is disabled (i.e., persistent_cache_size set to 0) and later re-enabled, all cached data will be invalidated. This is because data consistency cannot be guaranteed when the cache is turned off.

Parameter Settings

For detailed configuration of persistent cache settings, refer to the configuration documentation.