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

Safe HaskellNone

Data.TCache.IResource

Synopsis

Documentation

class IResource a whereSource

Must be defined for every object to be cached.

Methods

keyResourceSource

Arguments

:: a 
-> String

must be defined

readResourceByKey :: String -> IO (Maybe a)Source

Implements the database access and marshalling of the object. while the database access must be strict, the marshaling must be lazy if, as is often the case, some parts of the object are not really accesed. If the object contains DBRefs, this avoids unnecesary cache lookups. This method is called inside atomically blocks. Since STM transactions retry, readResourceByKey may be called twice in strange situations. So it must be idempotent, not only in the result but also in the effect in the database . However, because it is executed by safeIOToSTM it is guaranteed that the execution is not interrupted.

readResource :: a -> IO (Maybe a)Source

writeResource :: a -> IO ()Source

To write into persistent storage. It must be strict. Since STM transactions may retry, writeResource must be idempotent, not only in the result but also in the effect in the database. . However, because it is executed by safeIOToSTM it is guaranteed that the execution is not interrupted. All the new obbects are writeen to the database on synchromization, so writeResource must not autocommit. Commit code must be located in the postcondition. (see setConditions) Since there is no provision for rollback from failure in writing to persistent storage, writeResource must retry until success.

delResource :: a -> IO ()Source

Delete the resource. It is called syncronously. So it must tocommit

Instances

(Typeable a, Indexable a, Serializable a) => IResource a 
IResource IndexText 
Queriable reg a => IResource (Index reg a) 
(Indexable a, Typeable a) => IResource (Cached a b) 

data Resources a b Source

Resources data definition used by withSTMResources

Constructors

Retry

forces a retry

Resources 

Fields

toAdd :: [a]

resources to be inserted back in the cache

toDelete :: [a]

resources to be deleted from the cache and from permanent storage

toReturn :: b

result to be returned

resources :: Resources a ()Source

Empty resources: resources= Resources [] [] ()