Safe Haskell | None |
---|
some internal definitions. To use default persistence, use
DefaultPersistence
instead
- type AccessTime = Integer
- type ModifTime = Integer
- data Status a
- = NotRead
- | DoNotExist
- | Exist a
- data Elem a = Elem !a !AccessTime !ModifTime
- type TPVar a = TVar (Status (Elem a))
- data DBRef a = DBRef !String !(TPVar a)
- castErr :: (Typeable a, Typeable a1) => a -> a1
- class Indexable a where
- class Serializable a where
- serialize :: a -> ByteString
- deserialize :: ByteString -> a
- setPersist :: a -> Persist
- data Persist = Persist {}
- defaultPersist :: Persist
- getPersist :: Serializable a => a -> IO Persist
- defaultReadByKey :: String -> IO (Maybe ByteString)
- defaultWrite :: String -> ByteString -> IO ()
- safeWrite :: [Char] -> ByteString -> IO ()
- defaultDelete :: String -> IO ()
- defReadResourceByKey :: (Serializable a, Indexable a) => [Char] -> IO (Maybe a)
- defWriteResource :: (Serializable a, Indexable a) => a -> IO ()
- defDelResource :: (Serializable a, Indexable a) => a -> IO ()
- readFileStrict :: FilePath -> IO ByteString
Documentation
type AccessTime = IntegerSource
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
:: a | |
-> String | additional extension for default file paths. IMPORTANT: defPath must depend on the datatype, not the value (must be constant). Default is .tcachedata/ |
class Serializable a whereSource
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 = show deserialize= read
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 -> ByteStringSource
deserialize :: ByteString -> aSource
:: a | |
-> Persist |
|
a persist mechanism has to implement these three primitives
defaultpersist
is the default file persistence
defaultPersist :: PersistSource
Implements default persistence of objects in files with their keys as filenames
getPersist :: Serializable a => a -> IO PersistSource
defaultReadByKey :: String -> IO (Maybe ByteString)Source
defaultWrite :: String -> ByteString -> IO ()Source
safeWrite :: [Char] -> ByteString -> IO ()Source
defaultDelete :: String -> IO ()Source
defReadResourceByKey :: (Serializable a, Indexable a) => [Char] -> IO (Maybe a)Source
defWriteResource :: (Serializable a, Indexable a) => a -> IO ()Source
defDelResource :: (Serializable a, Indexable a) => a -> IO ()Source
readFileStrict :: FilePath -> IO ByteStringSource
Strict read from file, needed for default file persistence