TCache-0.13.3: A Transactional cache with user-defined persistence
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.TCache.Defs

Description

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

Synopsis

Documentation

data Status a Source #

Constructors

NotRead 
DoNotExist 
Exist a 

data Elem a Source #

Constructors

Elem !a !AccessTime !ModifTime 

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

data DBRef a Source #

Constructors

DBRef !String !(TPVar a) 

Instances

Instances details
(IResource a, Typeable a) => Read (DBRef a) Source # 
Instance details

Defined in Data.TCache

Show (DBRef a) Source # 
Instance details

Defined in Data.TCache.Defs

Methods

showsPrec :: Int -> DBRef a -> ShowS #

show :: DBRef a -> String #

showList :: [DBRef a] -> ShowS #

Eq (DBRef a) Source # 
Instance details

Defined in Data.TCache.Defs

Methods

(==) :: DBRef a -> DBRef a -> Bool #

(/=) :: DBRef a -> DBRef a -> Bool #

Ord (DBRef a) Source # 
Instance details

Defined in Data.TCache.Defs

Methods

compare :: DBRef a -> DBRef a -> Ordering #

(<) :: DBRef a -> DBRef a -> Bool #

(<=) :: DBRef a -> DBRef a -> Bool #

(>) :: DBRef a -> DBRef a -> Bool #

(>=) :: DBRef a -> DBRef a -> Bool #

max :: DBRef a -> DBRef a -> DBRef a #

min :: DBRef a -> DBRef a -> DBRef a #

castErr :: (Typeable a1, Typeable a2) => a1 -> a2 Source #

class Indexable a where Source #

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 Source #

defPath Source #

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

Instances details
Indexable String Source # 
Instance details

Defined in Data.TCache.Defs

Indexable Integer Source # 
Instance details

Defined in Data.TCache.Defs

Indexable () Source # 
Instance details

Defined in Data.TCache.Defs

Methods

key :: () -> String Source #

defPath :: () -> String Source #

Indexable Int Source # 
Instance details

Defined in Data.TCache.Defs

class Serializable a where Source #

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 Source #

deserialize :: ByteString -> a Source #

deserialKey :: String -> ByteString -> a Source #

setPersist Source #

Arguments

:: a 
-> Maybe Persist

defaultPersist if Nothing

class PersistIndex a where Source #

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

Instances

Instances details
Serializable a => PersistIndex a Source #

By default the index of a Serializable data persist with the data.

Instance details

Defined in Data.TCache.DefaultPersistence

data Persist Source #

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

Constructors

Persist 

Fields

filePersist :: Persist Source #

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

setDefaultPersist :: Persist -> IO () Source #

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 Source #

Strict read from file, needed for default file persistence