Skip to content

Releases: GtechGovind/CCache

CCache

Choose a tag to compare

@GtechGovind GtechGovind released this 23 Nov 05:57
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

Choose a tag to compare

@GtechGovind GtechGovind released this 22 Nov 15:56

Change Log:

Version 1.1 (Updated Version)

New Features and Improvements:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.
  11. 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.4

Choose a tag to compare

@GtechGovind GtechGovind released this 22 Nov 14:07

Here's the updated changelog reflecting the addition of std::optional support:

Changelog:

  • Added clear method:

    • A new method clear() was added to the CCache class to remove all entries from the cache. It clears both cache_map_ and access_order_ and logs the action if a logger is provided.
  • Updated cache return types to std::optional<Value>:

    • The get method now returns std::optional<Value> instead of just Value. 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_cache method also returns std::optional<Value>, making it consistent with the cache retrieval logic and enabling proper handling of cache misses.

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

Choose a tag to compare

@GtechGovind GtechGovind released this 22 Nov 13:24

Full Changelog: 0.0.1...0.0.3

CCache v0.0.2

Choose a tag to compare

@GtechGovind GtechGovind released this 22 Nov 13:17

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

Choose a tag to compare

@GtechGovind GtechGovind released this 22 Nov 12:14

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_cache Method: 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_mutex to ensure safe concurrent access to the cache.
  • Versioning: Added versioning support with CCACHE_VERSION_MAJOR, CCACHE_VERSION_MINOR, and CCACHE_VERSION_PATCH constants.