ConcurrentStore

High-performance thread-safe in-memory cache store using concurrent hash maps

The ConcurrentStore is the default and most commonly used object store in BoxCache. It provides high-performance, thread-safe in-memory caching using Java's ConcurrentHashMap for optimal concurrent access patterns. This store is ideal for frequently accessed data that doesn't need to persist across application restarts.

✨ Features

  • High Performance: Lightning-fast read/write operations using concurrent hash maps

  • Thread-Safe: Built-in concurrency control for multi-threaded environments

  • Memory-Based: Stores all data in RAM for maximum speed

  • Eviction Support: Compatible with all BoxCache eviction policies (LRU, LFU, FIFO, LIFO, RANDOM)

  • No External Dependencies: Pure in-memory storage with no disk or database requirements

📋 Configuration Example

"myCache": {
    "provider": "BoxCacheProvider",
    "properties": {
        "objectStore": "ConcurrentStore",
        "maxObjects": 1000,
        "evictionPolicy": "LRU",
        "evictCount": 100,
        "defaultTimeout": 3600,
        "defaultLastAccessTimeout": 1800,
        "reapFrequency": 300
    }
}

⚙️ Configuration Properties

The ConcurrentStore uses all standard BoxCache properties and has no store-specific configuration options. All caching behavior is controlled through the global BoxCache properties:

The maximum number of objects to store in the cache. Default is 1000.

evictionPolicy

The eviction policy to use when the cache reaches capacity. Options: LRU, LFU, FIFO, LIFO, RANDOM. Default is LRU.

evictCount

How many objects to evict when the cache reaches capacity. Default is 1.

defaultTimeout

The maximum time in seconds to keep an object in the cache regardless of access. 0 = never expire. Default is 3600 (1 hour).

defaultLastAccessTimeout

The maximum time in seconds since last access before an object expires. Default is 1800 (30 minutes).

reapFrequency

How often (in seconds) to check for and remove expired objects. Default is 120 (2 minutes).

resetTimeoutOnAccess

If true, the last access timeout resets on every access (session-like behavior). Default is false.

useLastAccessTimeouts

If true, the last access timeout is used for eviction. Default is true.

freeMemoryPercentageThreshold

Trigger eviction when free memory falls below this percentage (0-100). 0 = disabled. Default is 0.

💡 Usage Examples

High-Performance Application Cache

Query Result Cache

API Response Cache

🎯 Best Practices

Performance Tips:

  • Set maxObjects based on your memory availability and data size

  • Use LRU eviction for most general-purpose caching scenarios

  • Tune reapFrequency based on your cache churn rate (lower for high churn)

  • Monitor memory usage and adjust freeMemoryPercentageThreshold if needed

  • Consider evictCount for bulk eviction when cache pressure is high

Last updated

Was this helpful?