diff --git a/filecache.cabal b/filecache.cabal
--- a/filecache.cabal
+++ b/filecache.cabal
@@ -1,5 +1,5 @@
 name:                filecache
-version:             0.5.0
+version:             0.5.1
 synopsis:            A cache system associating values to files.
 description:         A cache system, that works by associating computation results with file names. When the files are modified, the cache entries are discarded.
 homepage:            http://lpuppet.banquise.net/
@@ -12,6 +12,7 @@
 build-type:          Simple
 cabal-version:       >=1.10
 bug-reports:         https://github.com/bartavelle/filecache/issues
+tested-with:         GHC == 9.8.1 || ==9.6.4 || ==9.4.8 || ==9.2.8
 
 source-repository head
   type: git
diff --git a/src/Data/FileCache.hs b/src/Data/FileCache.hs
--- a/src/Data/FileCache.hs
+++ b/src/Data/FileCache.hs
@@ -9,6 +9,6 @@
 
 The computation will be used to populate the cache if this call results in a miss. The result is forced to WHNM.
 -}
-module Data.FileCache (FileCache, FileCacheR, newFileCache, killFileCache, invalidate, query, getCache, lazyQuery) where
+module Data.FileCache (FileCache, FileCacheR, newFileCache, killFileCache, invalidate, query, OnModified, queryWith, getCache, lazyQuery) where
 
 import Data.FileCache.Internal
diff --git a/src/Data/FileCache/Internal.hs b/src/Data/FileCache/Internal.hs
--- a/src/Data/FileCache/Internal.hs
+++ b/src/Data/FileCache/Internal.hs
@@ -26,7 +26,7 @@
 -- type must be an instance of 'Error'.
 data FileCacheR r a
     = FileCache
-    { _cache        :: TVar (M.Map FilePath (R.Either r a))
+    { _cache        :: TVar (M.Map FilePath (R.Either r a, OnModified))
     , _watchedDirs  :: TVar (M.Map FilePath (S.Set FilePath, StopListening))
     , _manager      :: WatchManager
     , _channel      :: EventChannel
@@ -36,6 +36,10 @@
 -- | A default type synonym, for String errors.
 type FileCache = FileCacheR String
 
+-- | Hook to invoke after an entry is removed from the cache
+-- (because the corresponding file has been modified)
+type OnModified = IO ()
+
 -- | Generates a new file cache. The opaque type is for use with other
 -- functions.
 newFileCache :: IO (FileCacheR r a)
@@ -49,9 +53,10 @@
       let cfp = eventPath e
           dir = addTrailingPathSeparator (takeDirectory cfp)
       join $ atomically $ do
+        onModified <- maybe (return ()) snd . M.lookup cfp <$> readTVar tcache
         modifyTVar tcache $ M.delete cfp
         wdirs <- readTVar wcache
-        case M.lookup dir wdirs of
+        (onModified >>) <$> case M.lookup dir wdirs of
           Nothing -> return $ return ()
           Just (watched, stop) ->
             let watched' = S.delete cfp watched
@@ -88,7 +93,16 @@
       -> FilePath -- ^ Path of the file entry
       -> IO (R.Either e a) -- ^ The computation that will be used to populate the cache
       -> IO (R.Either e a)
-query f@(FileCache tcache twatched wm chan tmtid) fp action = do
+query q fp = queryWith q fp (return ())
+
+-- | Generalization of 'query' that allows to specify an 'OnModified' hook
+queryWith :: forall e a. IsString e
+          => FileCacheR e a
+          -> FilePath -- ^ Path of the file entry
+          -> OnModified
+          -> IO (R.Either e a) -- ^ The computation that will be used to populate the cache
+          -> IO (R.Either e a)
+queryWith f@(FileCache tcache twatched wm chan tmtid) fp onModified action = do
   mtid <- readTVarIO tmtid
   case mtid of
     Nothing -> return (R.Left (fromString "Closed cache"))
@@ -105,7 +119,7 @@
         withWatch canonical value = value <$ (addWatch canonical value `catchAll` traceShowM )
         addWatch canonical value = join $ atomically $ do
           let cpath = addTrailingPathSeparator (takeDirectory canonical)
-          modifyTVar tcache (M.insert canonical value)
+          modifyTVar tcache (M.insert canonical (value, onModified))
           watched <- readTVar twatched
           case M.lookup cpath watched of
             Nothing -> return $ do
@@ -131,5 +145,4 @@
 
 -- | Gets a copy of the cache.
 getCache :: FileCacheR e a -> IO (M.Map FilePath (R.Either e a))
-getCache = atomically . readTVar . _cache
-
+getCache = atomically . fmap (fmap fst) . readTVar . _cache
