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

Safe HaskellNone

Data.TCache.Defs

Description

some internal definitions. To use default persistence, use DefaultPersistence instead

Synopsis

Documentation

data Status a Source

Constructors

NotRead 
DoNotExist 
Exist a 

Instances

data Elem a Source

Constructors

Elem !a !AccessTime !ModifTime 

Instances

type TPVar a = TVar (Status (Elem a))Source

data DBRef a Source

Constructors

DBRef !String !(TPVar a) 

Instances

Typeable1 DBRef 
Eq (DBRef a) 
Ord (DBRef a) 
(IResource a, Typeable a) => Read (DBRef a) 
Show (DBRef a) 
Queriable reg a => RelationOps (reg -> a) a [DBRef reg] 
(Typeable reg, IResource reg) => Select (reg -> a) (STM [DBRef reg]) (STM [a]) 
(Typeable reg, IResource reg, Select (reg -> a) (STM [DBRef reg]) (STM [a]), Select (reg -> b) (STM [DBRef reg]) (STM [b])) => Select (reg -> a, reg -> b) (STM [DBRef reg]) (STM [(a, b)]) 
(Typeable reg, IResource reg, Select (reg -> a) (STM [DBRef reg]) (STM [a]), Select (reg -> b) (STM [DBRef reg]) (STM [b]), Select (reg -> c) (STM [DBRef reg]) (STM [c])) => Select (reg -> a, reg -> b, reg -> c) (STM [DBRef reg]) (STM [(a, b, c)]) 
(Typeable reg, IResource reg, Select (reg -> a) (STM [DBRef reg]) (STM [a]), Select (reg -> b) (STM [DBRef reg]) (STM [b]), Select (reg -> c) (STM [DBRef reg]) (STM [c]), Select (reg -> d) (STM [DBRef reg]) (STM [d])) => Select (reg -> a, reg -> b, reg -> c, reg -> d) (STM [DBRef reg]) (STM [(a, b, c, d)]) 

castErr :: (Typeable a, Typeable a1) => a -> a1Source

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. 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.

Methods

serialize :: a -> ByteStringSource

deserialize :: ByteString -> aSource

setPersistSource

Arguments

:: a 
-> Persist

defaultPersistif not overriden

data Persist Source

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

Constructors

Persist

delete

Fields

readByKey :: String -> IO (Maybe ByteString)

read by key. It must be strict

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

write. It must be strict

delete :: String -> IO ()
 

defaultPersist :: PersistSource

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

readFileStrict :: FilePath -> IO ByteStringSource

Strict read from file, needed for default file persistence