diff options
Diffstat (limited to 'src/Cache.hs')
| -rw-r--r-- | src/Cache.hs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/Cache.hs b/src/Cache.hs index 4694aa0..d272112 100644 --- a/src/Cache.hs +++ b/src/Cache.hs @@ -26,6 +26,10 @@ cacheAdd cache@(Cache maxsize ref _) key val = do cacheLookup :: Ord k => Cache k v -> k -> IO (Maybe v) cacheLookup (Cache _ ref _) key = fmap fst . Map.lookup key <$> readIORef ref +cacheInvalidate :: Ord k => Cache k v -> k -> IO () +cacheInvalidate (Cache _ ref _) key = + atomicModifyIORef' ref $ \mp -> (Map.delete key mp, ()) + -- Uses 2-random LRU (https://danluu.com/2choices-eviction/) cachePrune :: Ord k => Cache k v -> IO () cachePrune (Cache maxsize ref genref) = do go =<< atomicModifyIORef' genref splitGen |
