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.
"maxObjects": 5000evictionPolicy
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": 100defaultTimeout
The maximum time in seconds to keep an object in the cache regardless of access. 0 = never expire. Default is 3600 (1 hour).
"defaultTimeout": 7200defaultLastAccessTimeout
The maximum time in seconds since last access before an object expires. Default is 1800 (30 minutes).
"defaultLastAccessTimeout": 3600reapFrequency
How often (in seconds) to check for and remove expired objects. Default is 120 (2 minutes).
"reapFrequency": 300resetTimeoutOnAccess
If true, the last access timeout resets on every access (session-like behavior). Default is false.
"resetTimeoutOnAccess": trueuseLastAccessTimeouts
If true, the last access timeout is used for eviction. Default is true.
"useLastAccessTimeouts": truefreeMemoryPercentageThreshold
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
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?
