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.

"maxObjects": 5000

evictionPolicy

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

"evictionPolicy": "LRU"

evictCount

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

"evictCount": 100

defaultTimeout

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

"defaultTimeout": 7200

defaultLastAccessTimeout

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

"defaultLastAccessTimeout": 3600

reapFrequency

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

"reapFrequency": 300

resetTimeoutOnAccess

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

"resetTimeoutOnAccess": true

useLastAccessTimeouts

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

"useLastAccessTimeouts": true

freeMemoryPercentageThreshold

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

"freeMemoryPercentageThreshold": 10

💡 Usage Examples

High-Performance Application Cache

"appCache": {
    "provider": "BoxCacheProvider",
    "properties": {
        "objectStore": "ConcurrentStore",
        "maxObjects": 10000,
        "evictionPolicy": "LRU",
        "evictCount": 500,
        "defaultTimeout": 3600,
        "reapFrequency": 300
    }
}

Query Result Cache

"queryCache": {
    "provider": "BoxCacheProvider",
    "properties": {
        "objectStore": "ConcurrentStore",
        "maxObjects": 5000,
        "evictionPolicy": "LFU",
        "defaultTimeout": 1800,
        "defaultLastAccessTimeout": 900
    }
}

API Response Cache

"apiCache": {
    "provider": "BoxCacheProvider",
    "properties": {
        "objectStore": "ConcurrentStore",
        "maxObjects": 2000,
        "evictionPolicy": "LRU",
        "defaultTimeout": 600,
        "freeMemoryPercentageThreshold": 15
    }
}

🎯 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?