Skip to content

An implementation of a cache that will regenerate a value if accessed after a certain amount of time.

License

Notifications You must be signed in to change notification settings

Plasticcaz/timed_cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Timed Cache

This library is an implementation of a cache that stores its contents by a key, as well as the duration of time that value will remain valid once it has been written to the cache.

If the value is missing when the user tries to retrieve a value from the TimedCache, or the value has outlived the specified storage Duration of the cache, the value will be regenerated using a specified function.

NOTE: In the current implementation, invalid values will remain in memory until the next time it is queried, and then a new value will be created. This may be considered a memory leak, though this was by design.

Example:

    let cache = TimedCache::with_time_to_keep(Duration::from_seconds(60));
    cache.get(&"key".to_owned(), || some_mutexed_service.lock().unwrap().call());

For information, please see the tests and documentation.

Contribution

I am more than willing to have help improving and extending this library. Please leave an issue and/or submit a pull request!

About

An implementation of a cache that will regenerate a value if accessed after a certain amount of time.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages