mirror of
https://github.com/ltcptgeneral/cs239-caching.git
synced 2026-02-03 06:31:02 +00:00
[ADD] - Added social media user profile get and upsert microservice with nosql database integration
This commit is contained in:
28
app/cache/prefetch_cache.py
vendored
Normal file
28
app/cache/prefetch_cache.py
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
from .cache import BaselineCache
|
||||
|
||||
class PrefetchCache(BaselineCache):
|
||||
key_relations = None
|
||||
|
||||
def __init__(self):
|
||||
super()
|
||||
self.key_relations = dict()
|
||||
|
||||
def put(self, key: str, val: str) -> bool:
|
||||
# LRU evict
|
||||
evict = False
|
||||
if len(self.cache) >= self.limit:
|
||||
self.cache.popitem(last = False)
|
||||
evict = True
|
||||
self.cache[key] = val
|
||||
self.prefetch(key, val)
|
||||
|
||||
return evict
|
||||
|
||||
def prefetch(self, key: str, val: str) -> bool:
|
||||
if len(self.cache) >= self.limit and key in self.key_relations:
|
||||
self.cache[self.key_relations[key][0]] = self.key_relations[key][1]
|
||||
return True
|
||||
return False
|
||||
|
||||
def set_relations(self):
|
||||
return
|
||||
Reference in New Issue
Block a user