Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class IResource a where
- keyResource :: a -> String
- readResourceByKey :: String -> IO (Maybe a)
- readResourcesByKey :: [String] -> IO [Maybe a]
- readResource :: a -> IO (Maybe a)
- writeResource :: a -> IO ()
- writeResources :: [a] -> IO ()
- delResource :: a -> IO ()
- delResources :: [a] -> IO ()
- data Resources a b
- resources :: Resources a ()
Documentation
class IResource a where Source #
Must be defined for every object to be cached.
:: 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 within 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.
readResourcesByKey :: [String] -> IO [Maybe a] Source #
hopefully optimized read of many objects by key.
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.
writeResources :: [a] -> IO () Source #
multiple write (hopefully) in a single request. That is up to you and your backend . Defined by default as 'mapM_ writeResource'
delResource :: a -> IO () Source #
Delete the resource. It is called syncronously. So it must commit
delResources :: [a] -> IO () Source #
Instances
(Typeable a, Indexable a, Serializable a) => IResource a Source # | |
Defined in Data.TCache.DefaultPersistence keyResource :: a -> String Source # readResourceByKey :: String -> IO (Maybe a) Source # readResourcesByKey :: [String] -> IO [Maybe a] Source # readResource :: a -> IO (Maybe a) Source # writeResource :: a -> IO () Source # writeResources :: [a] -> IO () Source # delResource :: a -> IO () Source # delResources :: [a] -> IO () Source # |
Resources data definition used by withSTMResources