hxt-cache-9.1.0: Cache for HXT XML Documents and other binary data

MaintainerUwe Schmidt (uwe@fh-wedel.de)
Safe HaskellNone



Caching of XML document trees and other binary data



withCache :: String -> Int -> Bool -> SysConfigSource

withCache enables reading documents with caching.

When the cache is configured and enabled, every document read and parsed is serialized and stored in binary form in the cache. When reading the same document again, it is just deserialized, no parsing is performed.

The cache is configured by a path pointing to a directory for storing the documents, by a maximal time span in second for valid documents. After that time span, the documents are read again and the cache is updated. The flag contols, whether documents returning 404 or other errors will be cached. If set, the cache is even activated for 404 (not found) responses, default is false.

The serialized documents can be compressed, e.g. with bzip, to save disk space and IO time. The compression can be configured by withCompression


 import Text.XML.HXT.Core
 import Text.XML.HXT.Cache
 import Codec.Compression.BZip (compress, decompress)
 readDocument [ withCache "/tmp/cache" 3600 False
              , withCompression (compress, decompress)
              , ....
              ] "http://www.haskell.org/"

In the example the document is read and stored in binary serialized form under /tmp/cache. The cached document remains valid for the next hour. It is compressed, before written to disk.

withoutCache :: SysConfigSource

Disable use of cache