This cache uses n daemon worker threads to distribute the workload of each job it is given and store up to n * lines items within a set associative cache.
pip3 install n_way_set_associative_cache
- Import the package
from n_way_set_associative_cache import NWaySetAssociativeCache as nwsac
- Create a new cache object
cache = nwsac.NWaySetAssociativeCache(n, replacement, lines)
n = the number of sets (and the number of worker threads)
replacement = 'LRU', 'MRU', or a custom static replacement algorithm. The custom replacement algorithm will take in the cache class instance, as well as the set number to do the replacement on as parameters.
lines = the number of lines within a single set
- When you attempt to get an item that does not exist within the cache, a ValueError will be thrown. A typical use case is as follows:
try:
data = cache.get(resource_key)
except ValueError:
data = method_to_retrieve_from_backing_store(resource_key)
cache.put(resource_key, data)
python3 NWaySetAssociativeCache.test.py