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

Safe HaskellNone
LanguageHaskell98

Data.TCache.Defs

Description

some internal definitions. To use default persistence, import Data.TCache.DefaultPersistence instead

Synopsis

Documentation

data Status a #

Constructors

NotRead 
DoNotExist 
Exist a 

data Elem a #

Constructors

Elem !a !AccessTime !ModifTime 

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

data DBRef a #

Constructors

DBRef !String !(TPVar a) 

castErr :: (Typeable * a, Typeable * p) => p -> a #

class Indexable a where #

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

Minimal complete definition

key

Methods

key :: a -> String #

defPath #

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/"

Instances

Indexable Int # 

Methods

key :: Int -> String #

defPath :: Int -> String #

Indexable Integer # 
Indexable () # 

Methods

key :: () -> String #

defPath :: () -> String #

Indexable String # 

Methods

key :: String -> String #

defPath :: String -> String #

class Serializable a where #

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  = pack . show
   deserialize= read . unpack

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

Minimal complete definition

serialize

Methods

serialize :: a -> ByteString #

deserialize :: ByteString -> a #

deserialKey :: String -> ByteString -> a #

setPersist #

Arguments

:: a 
-> Maybe Persist

defaultPersist if Nothing

class PersistIndex a where #

Used by IndexQuery for index persistence(see Data.TCache.IndexQuery.

Minimal complete definition

persistIndex

Methods

persistIndex :: a -> Maybe Persist #

type Key = String #

data Persist #

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

Constructors

Persist

delete

Fields

filePersist :: Persist #

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

setDefaultPersist :: Persist -> IO () #

Set the default persistence mechanism of all serializable objects that have setPersist= const Nothing. By default it is filePersist

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

readFileStrict :: FilePath -> IO ByteString #

Strict read from file, needed for default file persistence