Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
some internal definitions. To use default persistence, import
Data.TCache.DefaultPersistence
instead
Synopsis
- 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 a1, Typeable a2) => a1 -> a2
- class Indexable a where
- class Serializable a where
- serialize :: a -> ByteString
- deserialize :: ByteString -> a
- deserialKey :: String -> ByteString -> a
- setPersist :: a -> Maybe Persist
- class PersistIndex a where
- persistIndex :: a -> Maybe Persist
- type Key = String
- data Persist = Persist {}
- filePersist :: Persist
- defaultPersistIORef :: IORef Persist
- setDefaultPersist :: Persist -> IO ()
- getDefaultPersist :: Persist
- getPersist :: (Serializable a, Typeable a) => a -> Persist
- defaultReadByKey :: String -> IO (Maybe ByteString)
- defaultWrite :: String -> ByteString -> IO ()
- safeWrite :: FilePath -> ByteString -> IO ()
- defaultDelete :: String -> IO ()
- defReadResourceByKey :: (Indexable a, Serializable a, Typeable a) => String -> IO (Maybe a)
- defWriteResource :: (Indexable a, Serializable a, Typeable a) => a -> IO ()
- defDelResource :: (Indexable a, Serializable a, Typeable a) => a -> IO ()
- readFileStrict :: FilePath -> IO ByteString
Documentation
type AccessTime = Integer 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
:: 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 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 #
class PersistIndex a where Source #
Used by IndexQuery for index persistence(see Data.TCache.IndexQuery.
persistIndex :: a -> Maybe Persist Source #
Instances
Serializable a => PersistIndex a Source # | By default the index of a |
Defined in Data.TCache.DefaultPersistence persistIndex :: a -> Maybe Persist Source # |
a persist mechanism has to implement these three primitives
filePersist
is the default file persistence
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
getPersist :: (Serializable a, Typeable a) => a -> Persist Source #
defaultReadByKey :: String -> IO (Maybe ByteString) Source #
defaultWrite :: String -> ByteString -> IO () Source #
defaultDelete :: String -> IO () Source #
defReadResourceByKey :: (Indexable a, Serializable a, Typeable a) => String -> IO (Maybe a) Source #
defWriteResource :: (Indexable a, Serializable a, Typeable a) => a -> IO () Source #
defDelResource :: (Indexable a, Serializable a, Typeable a) => a -> IO () Source #
readFileStrict :: FilePath -> IO ByteString Source #
Strict read from file, needed for default file persistence