Repository navigation
Releases: GtechGovind/CCache
Releases · GtechGovind/CCache
Release list
CCache
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 EvictionCallback that 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. Logger Callback: Introduced an optional LoggerCallback to log cache operations like GET, PUT, UPDATE, EVICT, and CLEAR. This feature allows integration with logging systems and can be used for debugging or monitoring purposes. Improved Cache Entry Eviction: The eviction strategy now follows the Least Recently Used (LRU) approach. The evict_lru method removes the least recently accessed entry when the cache is full, ensuring optimal space usage. The evict method explicitly evicts an entry by key and invokes the eviction callback if provided. 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. Cache Hit/Miss Logging: Added logging for cache hits (HIT) and misses (MISS) in the with_cache method, improving transparency and enabling better monitoring of cache performance. Improved Function Names and Documentation: The function names and comments have been refined for clarity and professionalism. The method key_to_string now checks if the key is convertible to a std::string and 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_ and ttl_millis_ parameters, throwing an std::invalid_argument exception if they are non-positive. This ensures the cache is created with valid configuration values. Optional Cache Retrieval (with_cache): The with_cache method 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. Improved Access Order Management: The update_access_order method 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. Cache Entry Structure: The CacheEntry struct now encapsulates both the value and its timestamp, making it easier to manage cache entries and check for expiration. 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.
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.
CCache v0.0.4
Here's the updated changelog reflecting the addition of std::optional support:
Changelog:
-
Added
clearmethod:- A new method
clear()was added to theCCacheclass to remove all entries from the cache. It clears bothcache_map_andaccess_order_and logs the action if a logger is provided.
- A new method
-
Updated cache return types to
std::optional<Value>:- The
getmethod now returnsstd::optional<Value>instead of justValue. This change allows the method to return an empty state (i.e.,std::nullopt) when the key is not found or the cache entry has expired. - The
with_cachemethod also returnsstd::optional<Value>, making it consistent with the cache retrieval logic and enabling proper handling of cache misses.
- The
Example Usage of clear method:
CCache<int, std::string> cache;
cache.put(1, "value1");
cache.put(2, "value2");
// Clear all entries from the cache
cache.clear();Example of std::optional<Value> with get and with_cache:
auto value = cache.get(1);
if (value) {
// Value is found
std::cout << "Found: " << *value << std::endl;
} else {
// Value is not found or expired
std::cout << "Not found or expired" << std::endl;
}
auto computed_value = cache.with_cache(3, []() { return "computed_value"; });
std::cout << "Computed or fetched: " << computed_value.value() << std::endl;These changes introduce better error handling and caching behaviors through the use of std::optional.
CCacahe v0.0.3
CCache v0.0.2
Here’s a changelog based on the improvements and additions in your CMake configuration:
Changelog for CMake Configuration
Full Changelog: 0.0.1...0.0.2
CCache v0.0.1
Changelog
Added
- Initial release of
CCache, an in-memory, thread-safe, key-value cache. - Eviction Policies: Implemented Least Recently Used (LRU) eviction when the cache exceeds the specified maximum size (
max_size). - TTL (Time-To-Live): Cache entries expire after a specified time (
ttl_millis), automatically evicting expired entries. with_cacheMethod: Added a method that retrieves cached data or computes and caches the result if not already stored, optimizing redundant calculations.- Callback Functions:
- Eviction Callback: Invoked when an item is evicted from the cache.
- Logging Callback: Allows custom logging of cache operations (GET, PUT, EVICT, etc.).
- Thread Safety: Added
std::shared_mutexto ensure safe concurrent access to the cache. - Versioning: Added versioning support with
CCACHE_VERSION_MAJOR,CCACHE_VERSION_MINOR, andCCACHE_VERSION_PATCHconstants.