mirror of
https://github.com/reanimate/reanimate.git
synced 2026-09-14 09:32:22 +00:00
Use files rather than memory to store cached values.
This commit is contained in:
parent
b08fceeddb
commit
56157ad9c1
3 changed files with 41 additions and 37 deletions
30
server/Cache.hs
Normal file
30
server/Cache.hs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
module Cache (lookupCache, insertCache) where
|
||||
|
||||
import Control.Concurrent
|
||||
import Control.Exception
|
||||
import qualified Data.IntMap as M
|
||||
import System.Directory
|
||||
import System.FilePath
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.IO as T
|
||||
import Data.Text (Text)
|
||||
import Data.Hashable
|
||||
|
||||
valueFilePath :: Text -> IO FilePath
|
||||
valueFilePath key = do
|
||||
tmp <- getTemporaryDirectory
|
||||
return $ tmp </> "reanimate" ++ show (hash key) <.> "svgs"
|
||||
|
||||
|
||||
insertCache :: Text -> [Text] -> IO ()
|
||||
insertCache key value = do
|
||||
cacheFile <- valueFilePath key
|
||||
T.writeFile cacheFile (T.unlines value)
|
||||
|
||||
lookupCache :: Text -> IO (Maybe [Text])
|
||||
lookupCache key = do
|
||||
cacheFile <- valueFilePath key
|
||||
do svgs <- T.lines <$> T.readFile cacheFile
|
||||
evaluate (svgs)
|
||||
return (Just svgs)
|
||||
`catch` \SomeException{} -> return Nothing
|
||||
Loading…
Reference in a new issue