Skip to content

CCache v0.0.4

Choose a tag to compare

@GtechGovind GtechGovind released this 22 Nov 14:07
· 2 commits to master since this release

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.