TCache- A Transactional cache with user-defined persistence

Safe HaskellNone




class Indexable a whereSource

Indexable is an utility class used to derive instances of IResource


data Person= Person{ pname :: String, cars :: [DBRef Car]} deriving (Show, Read, Typeable)
data Car= Car{owner :: DBRef Person , cname:: String} deriving (Show, Read, Eq, Typeable)

Since Person and Car are instances of Read ans Show, by defining the Indexable instance will implicitly define the IResource instance for file persistence:

instance Indexable Person where  key Person{pname=n} = "Person " ++ n
instance Indexable Car where key Car{cname= n} = "Car " ++ n


key :: a -> StringSource



:: a 
-> String

additional extension for default file paths. IMPORTANT: defPath must depend on the datatype, not the value (must be constant). Default is .tcachedata/

class Serializable a whereSource

Serialize is an alternative to the IResource class for defining persistence in TCache. The deserialization must be as lazy as possible. serialization/deserialization are not performance critical in TCache

Read, Show, instances are implicit instances of Serializable

    serialize  = show
    deserialize= read

Since write and read to disk of to/from the cache are not be very frequent The performance of serialization is not critical.


serialize :: a -> ByteStringSource

deserialize :: ByteString -> aSource



:: a 
-> Maybe Persist

defaultPersist if Nothing

setDefaultPersist :: Persist -> IO ()Source

Set the default persistence mechanism of all serializable objetcts. By default it is filePersist

this statement must be the first one before any other TCache call

filePersist :: PersistSource

Implements default persistence of objects in files with their keys as filenames

data Persist Source

a persist mechanism has to implement these three primitives filePersist is the default file persistence





readByKey :: String -> IO (Maybe ByteString)

read by key. It must be strict

write :: String -> ByteString -> IO ()

write. It must be strict

delete :: String -> IO ()