Table of Contents
https://git.opendaylight.org/gerrit/#/q/topic:bug/8300 https://www.youtube.com/watch?v=h4HOSRN2aFc
Infrautils Caches provide a Cache of keys to values. The implementation of Infrautils Cache API is, typically, backed by established cache frameworks,such as Ehcache, Infinispan, Guava’s, Caffeine, …, imcache, cache2k, … etc.
Caches are not Maps!. Differences include that a Map persists all elements that are added to it until they are explicitly removed. A Cache on the other hand is generally configured to evict entries automatically, in order to constrain its memory footprint, based on some policy. Another notable difference, enforced by this caching API, is that caches should not be thought of as data structures that you put something in somewhere in your code to get it out of somewhere else. Instead, a Cache is “just a façade” to a CacheFunction’s get. This design enforces proper encapsulation, and helps you not to screw up the content of your cache (like you easily can, and usually do, when you use a Map as a cache).
This feature will support following use cases:
The proposed feature adds a new module in infrautils called “caches”, which will have the following functionalities:
N/A
Applications can define their own Cache, with specified CacheFunction and Policies. Caches can be configured to set the maximum entries and also to enable stats.
Cache is “just a façade” to a CacheFunction’s get(). When the user defines a CacheFunction for his cache, that will be executed whenever a get() is executed on the cache.
Anchor refers to instance of the class “containing” this Cache. It is used by CacheManagers to display to end-user.
Cache id is a short ID for this cache, and description will be a one line human readable description for the cache.
Cache Eviction Policy is based on the number of entries the cache can hold, which will be set during the cache creation time.
This feature is aiming at improving the scale and performance of applications by helping to define a CacheFunction for heavy operations.
Carbon.
Cache is currently neither distributed (cluster wide) nor transactional.”
N/A
odl-infrautils-caches odl-infrautils-caches-sample
Caches provides the below APIs which can be used by other applications:
CacheProvider APIs
<K, V> Cache<K, V> newCache(CacheConfig<K, V> cacheConfig, CachePolicy initialPolicy);
<K, V> Cache<K, V> newCache(CacheConfig<K, V> cacheConfig);
<K, V, E extends Exception> CheckedCache<K, V, E> newCheckedCache(
CheckedCacheConfig<K, V, E> cacheConfig, CachePolicy initialPolicy);
<K, V, E extends Exception> CheckedCache<K, V, E> newCheckedCache(CheckedCacheConfig<K, V, E> cacheConfig);
CacheManager APIs
BaseCacheConfig getConfig();
CacheStats getStats();
CachePolicy getPolicy();
void setPolicy(CachePolicy newPolicy);
void evictAll();
Appropriate UTs will be added for the new code coming in once framework is in place.
This will require changes to Developer Guide.
Developer Guide can capture the new set of APIs added by Caches as mentioned in API section.