mirror of
https://github.com/ltcptgeneral/cs239-caching.git
synced 2025-04-01 12:33:25 +00:00
20 lines
576 B
Python
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
|
|
|