Last updated
Was this helpful?
Last updated
Was this helpful?
The BoxCache Provider is BoxLang's default, high-performance cache implementation. It provides a comprehensive caching solution with pluggable object stores, configurable eviction policies, automatic maintenance, and extensive monitoring capabilities. The BoxCache Provider serves as the foundation for most caching needs in BoxLang applications.
The BoxCache Provider (BoxCacheProvider
) is designed to be:
High Performance: Uses efficient concurrent data structures and async operations
Flexible Storage: Supports multiple object store backends (memory, disk, custom)
Intelligent Eviction: Configurable eviction policies (LRU, MRU, LFU, etc.)
Self-Maintaining: Automatic expiration, reaping, and memory management
Event-Driven: Comprehensive event broadcasting for cache operations
Thread-Safe: Fully concurrent and thread-safe for multi-threaded applications
Observable: Rich statistics and monitoring capabilities
The primary way to access BoxCache instances in BoxLang is through the cache()
BIF:
The BoxCache Provider offers multiple ways to store data with flexible timeout options:
Basic Retrieval Patterns
Functional Transformations
Validation and Type Safety
Side Effects and Actions
Error Handling and Recovery
Stream Operations
Advanced Functional Patterns
Bulk Retrieval with Functional Processing
Silent Retrieval and Internal Operations
Filtered Retrieval with Complex Processing
The BoxCache Provider includes the powerful getOrSet()
method to eliminate double-lookup patterns:
Remove data from the cache with various options:
Cache filters provide powerful pattern matching for bulk operations:
Check for key existence without retrieving data:
The BoxCache Provider includes comprehensive statistics tracking:
Access and understand cache configuration:
BoxCache supports asynchronous operations for high-performance scenarios:
BoxCache automatically handles:
Expiration Checking: Removes expired entries based on timeouts
Idle Timeout Management: Removes entries that haven't been accessed
Memory Threshold Eviction: Triggers eviction when memory usage is high
Scheduled Reaping: Periodic cleanup based on reapFrequency
setting
BoxCache broadcasts events for all major operations:
The BoxCache Provider offers a comprehensive, high-performance caching solution for BoxLang applications. By leveraging its rich feature set including flexible storage options, intelligent eviction policies, comprehensive monitoring, and powerful filtering capabilities, developers can build scalable, efficient applications.
Key advantages of BoxCache Provider:
Developer Friendly: Simple BIF-based access with powerful functionality
High Performance: Concurrent operations, async support, and efficient data structures
Flexible Configuration: Pluggable object stores and eviction policies
Production Ready: Comprehensive monitoring, event integration, and automatic maintenance
Scalable: Supports everything from simple key-value caching to complex multi-level architectures
Whether you're caching user sessions, API responses, database queries, or computed data, the BoxCache Provider provides the tools and flexibility needed to optimize your application's performance and scalability.
Retrieve data with built-in null safety using the Attempt
pattern. Please see the construct section.
The BoxCache Provider is BoxLang's default, high-performance cache implementation.