TCache-0.9.0.3: A Transactional cache with user-defined persistence

Safe HaskellSafe-Infered

Data.TCache.DefaultPersistence

Description

This module provides default persistence , understood as retrievong and storing the object in serialized blobs but also to compose a SQL string and write it to a databases. for Indexable and serializable instances. The user can define it with setPersist. If the user does not set it, persistence in files is used.

Synopsis

Documentation

class Indexable a whereSource

Indexable is an utility class used to derive instances of IResource

Example:

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

Methods

key :: a -> StringSource

defPathSource

Arguments

:: a 
-> String

additional extension for default file paths. The default value is data/.

Instances

Indexable IndexText 
(Typeable reg, Typeable a) => Indexable (Index reg a) 

class Serializable a | a -> whereSource

Serialize is an abstract serialization ionterface in order to define implicit instances of IResource. The deserialization must be as lazy as possible if deserialized objects contain DBRefs, lazy deserialization avoid unnecesary DBRef instantiations when they are not accessed, since DBRefs instantiations involve extra cache lookups For this reason serializationdeserialization is tofrom ordinary Strings 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 must not be very often The performance of serialization is not critical.

Instances

Serializable IndexText 
Queriable reg a => Serializable (Index reg a) 

data Persist Source

Constructors

Persist

delete

Fields

readByKey :: String -> IO (Maybe ByteString)

read

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

write

delete :: String -> IO ()