diff options
| author | hallgren <hallgren@chalmers.se> | 2014-07-21 15:53:38 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2014-07-21 15:53:38 +0000 |
| commit | 3660339b231f4095b8251aa220103211d14c7913 (patch) | |
| tree | 6833c7ef87506422aa32f29965a92f1c66ac0025 /src/server/PGFService.hs | |
| parent | 1ba0c4b354e671fe2bafd1af8bef11ea09c543d6 (diff) | |
PGF service: expire PGFs from the cache when they have been unused for 24 hours
...to keep memory use down on the server.
Diffstat (limited to 'src/server/PGFService.hs')
| -rw-r--r-- | src/server/PGFService.hs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs index 509591ba2..316509d1f 100644 --- a/src/server/PGFService.hs +++ b/src/server/PGFService.hs @@ -53,21 +53,28 @@ type Caches = (Cache PGF,Cache (C.PGF,({-MVar ParseCache-}))) --type ParseCache = Map.Map (String,String) (ParseResult,UTCTime) --type ParseResult = Either String [(C.Expr,Float)] -newPGFCache = do pgfCache <- newCache PGF.readPGF - cCache <- newCache $ \ path -> do pgf <- C.readPGF path - --pc <- newMVar Map.empty - return (pgf,({-pc-})) +newPGFCache = do pgfCache <- newCache' PGF.readPGF + cCache <- newCache' $ \ path -> do pgf <- C.readPGF path + --pc <- newMVar Map.empty + return (pgf,({-pc-})) return (pgfCache,cCache) flushPGFCache (c1,c2) = flushCache c1 >> flushCache c2 listPGFCache (c1,c2) = (,) # listCache c1 % listCache c2 #else type Caches = (Cache PGF,()) -newPGFCache = do pgfCache <- newCache PGF.readPGF +newPGFCache = do pgfCache <- newCache' PGF.readPGF return (pgfCache,()) flushPGFCache (c1,_) = flushCache c1 listPGFCache (c1,_) = (,) # listCache c1 % return [] #endif +newCache' rd = do c <- newCache rd + forkIO $ forever $ clean c + return c + where + clean c = do threadDelay 2000000000 -- 2000 seconds, i.e. ~33 minutes + expireCache (24*60*60) c -- 24 hours + getPath = do path <- getVarWithDefault "PATH_TRANSLATED" "" -- apache mod_fastcgi if null path |
