diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-11-09 16:34:45 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-11-09 16:34:45 +0100 |
commit | 1319bbfe4ab3ddd321bcbb902bba7392ad868324 (patch) | |
tree | 5fdcad316015db237b18ff7e22e0e73c5044cc6f /src/Hakyll/Core/ResourceProvider/MetadataCache.hs | |
parent | dac3fac342c2fb8610b6f1d83cbfd97a70cf17f1 (diff) | |
download | hakyll-1319bbfe4ab3ddd321bcbb902bba7392ad868324.tar.gz |
Remove Resource type
Diffstat (limited to 'src/Hakyll/Core/ResourceProvider/MetadataCache.hs')
-rw-r--r-- | src/Hakyll/Core/ResourceProvider/MetadataCache.hs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/Hakyll/Core/ResourceProvider/MetadataCache.hs b/src/Hakyll/Core/ResourceProvider/MetadataCache.hs new file mode 100644 index 0000000..85062a0 --- /dev/null +++ b/src/Hakyll/Core/ResourceProvider/MetadataCache.hs @@ -0,0 +1,62 @@ +-------------------------------------------------------------------------------- +module Hakyll.Core.ResourceProvider.MetadataCache + ( resourceMetadata + , resourceBody + , resourceInvalidateMetadataCache + ) where + + +-------------------------------------------------------------------------------- +import Hakyll.Core.Identifier +import Hakyll.Core.Metadata +import Hakyll.Core.ResourceProvider.Internal +import Hakyll.Core.ResourceProvider.Metadata +import qualified Hakyll.Core.Store as Store + + +-------------------------------------------------------------------------------- +resourceMetadata :: ResourceProvider -> Identifier a -> IO Metadata +resourceMetadata rp r = do + load rp r + Store.Found md <- Store.get (resourceStore rp) + [name, toFilePath r, "metadata"] + return md + + +-------------------------------------------------------------------------------- +resourceBody :: ResourceProvider -> Identifier a -> IO String +resourceBody rp r = do + load rp r + Store.Found bd <- Store.get (resourceStore rp) + [name, toFilePath r, "body"] + maybe (resourceString r) return bd + + +-------------------------------------------------------------------------------- +resourceInvalidateMetadataCache :: ResourceProvider -> Identifier a -> IO () +resourceInvalidateMetadataCache rp r = do + Store.delete (resourceStore rp) [name, toFilePath r, "metadata"] + Store.delete (resourceStore rp) [name, toFilePath r, "body"] + + +-------------------------------------------------------------------------------- +load :: ResourceProvider -> Identifier a -> IO () +load rp r = do + mmd <- Store.get store mdk :: IO (Store.Result Metadata) + case mmd of + -- Already loaded + Store.Found _ -> return () + -- Not yet loaded + _ -> do + (metadata, body) <- loadMetadata rp r + Store.set store mdk metadata + Store.set store bk body + where + store = resourceStore rp + mdk = [name, toFilePath r, "metadata"] + bk = [name, toFilePath r, "body"] + + +-------------------------------------------------------------------------------- +name :: String +name = "Hakyll.Core.Resource.Provider.MetadataCache" |