1
0
mirror of https://github.com/ltcptgeneral/cs239-caching.git synced 2025-04-01 12:33:25 +00:00
cs239-caching/app/cache/read_after_write_cache.py
2025-03-02 19:41:55 -08:00

20 lines
576 B
Python

from .cache import BaselineCache
from database import get_user_profile
class ReadAfterWriteCache(BaselineCache):
def __init__(self, limit):
super().__init__( limit )
def invalidate(self, key: str) -> bool:
# basic delete invalidation, but after writing, we immediately read the value and add it to the cache
invalidated = False
if key in self.cache:
del self.cache[key]
invalidated = True
newData = get_user_profile( key )
self.put( key, newData )
return invalidated