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

Behavior Details:

  • set(): Always succeeds immediately, discards the value

  • get(): Always returns null (cache miss)

  • clear(): Always succeeds immediately (no-op)

  • getKeys(): Always returns empty array

  • getSize(): Always returns 0

  • lookup(): Always returns false (not found)

  • eviction: Never triggers (no data to evict)

  • expiration: Never occurs (no data to expire)

🧪 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.

Last updated

Was this helpful?