Safe Haskell | None |
---|---|
Language | Haskell98 |
This module decouples the 'IResource" class in two classes
one for key extraction Indexable
and other ('Serializable" for serlalization and persistence
.The last one defines persistence in files as default, but it can be changed
to persistence in databases, for example.
The definitions of these classes are in Defs.hs
- class Indexable a where
- class Serializable a where
- setDefaultPersist :: Persist -> IO ()
- getDefaultPersist :: Persist
- filePersist :: Persist
- data Persist = Persist {}
Documentation
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
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.
serialize :: a -> ByteString Source #
deserialize :: ByteString -> a Source #
deserialKey :: String -> ByteString -> a Source #
setPersist :: a -> Maybe Persist Source #
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
filePersist :: Persist Source #
Implements default default-persistence of objects in files with their keys as filenames
a persist mechanism has to implement these three primitives
filePersist
is the default file persistence
Orphan instances
(Typeable * a, Indexable a, Serializable a) => IResource a Source # | |
Serializable a => PersistIndex a Source # | By default the index of a |