BlackHoleStore
Mock cache store for testing and development that discards all data
The BlackHoleStore is a special-purpose mock cache store that simulates cache behavior without actually storing any data. All cache operations (set, get, clear) succeed immediately but no data is retained. This store is invaluable for testing, development, and performance benchmarking scenarios where you need to isolate application logic from caching concerns.
✨ Features
Zero Storage: No data is actually stored - all operations are no-ops
Instant Operations: All cache operations complete immediately with minimal overhead
Testing-Friendly: Perfect for unit tests and integration tests
Cache Simulation: Provides a valid cache interface without side effects
No Dependencies: No memory, disk, or database requirements
Performance Benchmarking: Isolate application performance from cache overhead
📋 Configuration Example
"mockCache": {
"provider": "BoxCacheProvider",
"properties": {
"objectStore": "BlackHoleStore"
}
}⚙️ Configuration Properties
The BlackHoleStore has no store-specific configuration properties and ignores all standard BoxCache properties since no data is stored. You can include standard BoxCache properties for compatibility, but they have no effect:
"testCache": {
"provider": "BoxCacheProvider",
"properties": {
"objectStore": "BlackHoleStore",
"maxObjects": 1000,
"evictionPolicy": "LRU",
"defaultTimeout": 3600
}
}All configuration properties are accepted but ignored since the BlackHoleStore never stores data.
💡 Usage Examples
Unit Testing Cache
"testCache": {
"provider": "BoxCacheProvider",
"properties": {
"objectStore": "BlackHoleStore"
}
}Development Environment
"devCache": {
"provider": "BoxCacheProvider",
"properties": {
"objectStore": "BlackHoleStore"
}
}Performance Benchmarking
"benchmarkCache": {
"provider": "BoxCacheProvider",
"properties": {
"objectStore": "BlackHoleStore"
}
}🎯 Best Practices
When to Use BlackHoleStore:
Unit Tests: Test cache-dependent code without actual caching side effects
Integration Tests: Isolate tests from cache state and persistence
Development: Quickly disable caching without code changes
Performance Testing: Measure application performance without cache overhead
Debugging: Isolate caching-related issues by disabling cache storage
CI/CD Pipelines: Fast test execution without cache setup/teardown
Important Considerations:
No Data Storage: All cached data is immediately discarded
Always Cache Miss: All get operations return null/not found
Not for Production: Never use in production environments
Testing Only: Designed exclusively for testing and development
No Persistence: Obviously provides no persistence across restarts
No Distribution: Not distributed (but also not local - it's nowhere!)
🧪 Testing Patterns
Testing Cache-Dependent Code
// Application code works the same way
cache = cacheGet( "testCache" );
// Set always succeeds (but stores nothing)
cache.set( "key", "value" );
// Get always returns null (cache miss)
result = cache.get( "key" ); // null
// Your code should handle cache misses gracefully
if ( isNull( result ) ) {
result = loadFromDatabase();
}Performance Benchmarking
// Benchmark with caching
cache = cacheGet( "realCache" );
startTime = getTickCount();
for ( i = 1; i <= 10000; i++ ) {
cache.set( "key_#i#", generateData() );
}
cacheTime = getTickCount() - startTime;
// Benchmark without caching overhead
cache = cacheGet( "blackHoleCache" );
startTime = getTickCount();
for ( i = 1; i <= 10000; i++ ) {
cache.set( "key_#i#", generateData() );
}
noCacheTime = getTickCount() - startTime;
// Compare results
cacheOverhead = cacheTime - noCacheTime;Environment-Specific Configuration
Use the BlackHoleStore in specific environments by configuring different cache providers:
// Application.bx
this.caches = {
"myCache": {
"provider": "BoxCacheProvider",
"properties": {
// Production: Use real cache
"objectStore": isProduction() ? "ConcurrentStore" : "BlackHoleStore",
"maxObjects": 1000,
"evictionPolicy": "LRU"
}
}
};🔍 Implementation Notes
The BlackHoleStore implements the full BoxCache object store interface but all operations are optimized to do nothing:
Zero Allocation: No memory allocation for cached objects
No I/O: No disk or network operations
Minimal CPU: Operations complete in nanoseconds
Thread-Safe: Safe for concurrent access (by doing nothing!)
GC-Friendly: Generates no garbage for collection
This makes it perfect for high-iteration tests where actual cache storage would create overhead or side effects.
🔗 Related Resources
ConcurrentStore - For real in-memory caching
FileSystemStore - For persistent caching
JDBCStore - For distributed caching
Last updated
Was this helpful?
