Repository navigation
CCache v0.0.5
Change Log:
Version 1.1 (Updated Version)
New Features and Improvements:
-
Detailed Comments:
- Added comprehensive comments throughout the class to describe the functionality of each method, parameter, and return type. This enhances code readability and maintainability.
-
Eviction Callback:
- Added an optional
EvictionCallbackthat is invoked when a cache entry is evicted. This callback provides flexibility to handle evictions, such as logging or additional actions when an entry is removed.
- Added an optional
-
Logger Callback:
- Introduced an optional
LoggerCallbackto log cache operations likeGET,PUT,UPDATE,EVICT, andCLEAR. This feature allows integration with logging systems and can be used for debugging or monitoring purposes.
- Introduced an optional
-
Improved Cache Entry Eviction:
- The eviction strategy now follows the Least Recently Used (LRU) approach. The
evict_lrumethod removes the least recently accessed entry when the cache is full, ensuring optimal space usage. - The
evictmethod explicitly evicts an entry by key and invokes the eviction callback if provided.
- The eviction strategy now follows the Least Recently Used (LRU) approach. The
-
Enhanced Thread Safety:
- The class now uses a shared mutex (
std::shared_mutex) to allow concurrent reads while ensuring thread safety during writes. This is ideal for scenarios with frequent reads and occasional writes.
- The class now uses a shared mutex (
-
Cache Hit/Miss Logging:
- Added logging for cache hits (
HIT) and misses (MISS) in thewith_cachemethod, improving transparency and enabling better monitoring of cache performance.
- Added logging for cache hits (
-
Improved Function Names and Documentation:
- The function names and comments have been refined for clarity and professionalism.
- The method
key_to_stringnow checks if the key is convertible to astd::stringand provides a string representation for logging purposes, supporting both string and non-string key types.
-
Validation of Parameters in Constructor:
- The constructor validates the
max_size_andttl_millis_parameters, throwing anstd::invalid_argumentexception if they are non-positive. This ensures the cache is created with valid configuration values.
- The constructor validates the
-
Optional Cache Retrieval (with_cache):
- The
with_cachemethod provides a mechanism to fetch a value from the cache or compute and insert it if not present. This allows for lazy computation while ensuring the result is cached for future use.
- The
-
Improved Access Order Management:
- The
update_access_ordermethod ensures the cache maintains accurate access order for LRU eviction, pushing accessed keys to the back of the order list to mark them as most recently used.
- The
-
Cache Entry Structure:
- The
CacheEntrystruct now encapsulates both the value and its timestamp, making it easier to manage cache entries and check for expiration.
- The
Bug Fixes:
- None identified in this release.
Backward Compatibility:
- This update maintains backward compatibility with previous versions of the class, although the new logging and eviction callback features provide enhanced functionality.