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:
maxObjects (recommended)
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
When to Use ConcurrentStore:
High-traffic applications requiring fast cache access
Frequently accessed data that changes regularly
Query caching and API response caching
Session-like data that doesn't need persistence
Development and testing environments
Important Considerations:
Not Persistent: All cached data is lost on application restart
Memory Usage: Stored objects consume heap memory - monitor JVM heap size
Not Distributed: Each application instance maintains its own cache
Garbage Collection: Large caches can impact GC performance - tune appropriately
🔗 Related Resources
ConcurrentSoftReferenceStore - Memory-sensitive alternative
FileSystemStore - For persistent caching needs
JDBCStore - For distributed caching scenarios
Last updated
Was this helpful?
