mirror of
https://github.com/ltcptgeneral/cs239-caching.git
synced 2025-09-23 15:10:19 +00:00
Added ReadAfterWrite
This commit is contained in:
20
app/cache/read_after_write_cache.py
vendored
Normal file
20
app/cache/read_after_write_cache.py
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
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
|
||||
|
Reference in New Issue
Block a user