ge      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdResources returned by withSTMResources' +resources to be inserted back in the cache Bresources to be deleted from the cache and from permanent storage result to be returned forces a retry >Interface that must be defined for every object being cached.   and L are implemented by default as read-write to files with its key as filename    and  V are specified just to allow these defaults. If you define your own persistence, then   serialize and  deserialize are not needed. The package Workflow need them anyway. 8minimal definition: keyResource, serialize, deserialize zWhile serialize and deserialize are agnostic about the way of converison to strings, either binary or textual, treadp and utshowp use the monad defined in the RefSerialize package. Both ways of serialization are alternative. one is defined oby default in terms of the other. the RefSerialize monad has been introduced to permit IResource objects to be fserialized as part of larger structures that embody them. This is necessary for the Workdlow package. \The keyResource string must be a unique since this is used to index it in the hash table. dwhen accessing a resource, the user must provide a partial object for wich the key can be obtained.  for example:  Adata Person= Person{name, surname:: String, account :: Int ....)   keyResource Person n s ...= n++sTthe data being accesed must have the fields used by keyResource filled. For example   readResource Person {name=John , surname= Adams})leaving the rest of the fields undefined JIResource has defaults definitions for all the methods except keyResource h Either one or other serializer must be defiened for default witeResource, readResource and delResource must be defined must be defined by the user must be defined by the user serializer in the  RefSerializeR monad. Either one or other serializer must be defined to use default persistence (deserialize in the RefSerilzlize monad. =additional extension for default file paths or key prefixes  resources= Resources [] [] () e    JKey datatype can be used to read any object trough the Dynamic interface.   data Key = Key f String deriving TypeableExample  mst <-  getDResource $  type keyofDesiredObject  case mst of " Nothing -> error $ " not found "++ key @ Just (idyn) -> fromIDyn idyn :: DesiredDatatype}DynamicInterface groups a set of default method calls to handle dynamic objects. It is not necessary to derive instances from it &encapsulates data in a dynamic object Mregisters the deserialize, readp and readResource methods for this data type Qextract the data from the dynamic object. trows a user error when the cast fails unsafe version. safe extraction with Maybe  g  hijklm Xset the cache. this is useful for hot loaded modules that will update an existing cache !")newCache creates a new cache #UgetTMVars return the TMVar that wraps the resources for which the keys are given . H | it return Nothing if a TMVar with this object has not been allocated E These TMVars can be used in explicit user constructed atomic blocks [ Additionally, the TMVars remain in the cache and can be accessed and updated by the rest  of the TCache methods. z the content of the TMVars are written every time the cache is syncronized with the storage until releaseTMVars is called nnreleaseTMVars permits the TMVars captured by getTMVars to be released. so they can be discarded when not used I Use this when you no longer need to use them directly in atomic blocks. $tgetTMVarsIO does not search for a TMVar in the cache like getTMVars. Instead of this getTMVarsIO creates a list of l TMVars with the content given in the list of resourcees and add these TMVars to the cache and return them. z the content of the TMVars are written every time the cache is syncronized with the storage until releaseTMVars is called %zthis is the main function for the *Resources primitivas, all the rest derive from it. the Res structure processed by the  with*Resources primitives are more efficient for cached TMVars because the internal loop is never retried, since all the necessary { resources at the beginning so no costly retries are necessary. The advantage increases with the complexity of the process = function passed to withSTMResources is interpreted as such: P -toUpdate secton is used to update the retrieved resources in the same order. } if the resource dont exist, it is created. Nothing means do nothing as usual. extra resources are not considered, $ it uses the rules of zip. ^ -toAdd: additional resources not read in the first parameter of withSTMResources are created/updated with toAdd  -toDelete: obvious ) -toReturn: will be returned by the call &the list of resources to be retrieved OThe function that process the resources found and return a Resources structure #The return value in the STM monad. &'update of a single object in the cache P :: (IResource a)=> a same as withResources , but for one only object  -> ([Maybe a]-> a) " -> IO () 'to atomically add/!modify many objects in the cache  :: (IResource a)=> [a]- list of resources to be retrieve  -> ([Maybe a]-> [a]=) function that process the retrieved resources P -> IO () and return a list of objects to be inserted/ modified )"to read a resource from the cache o=delete the resource from cache and from persistent storage Ddelete the list of resources from cache and from persistent storage p,Cstart the thread that clean and writes on the persistent storage. S Otherwise, clearSyncCache must be invoked explicitly or no persistence will exist P :: (IResource a) =>Cache a --The cache reference D -> Int --number of seconds betwen checks d -> (Integer-> Integer-> Bool) --The user-defined check-for-cleanup-from-cache for each object C(when this function return True, the object is removed from cache) g -> Int --The max number of objects in the cache, if more, the cleanup start E -> >IO ThreadId --Identifier of the thread created qHforce the atomic write of all the cached objects into permanent storage  useful for termination %Saves the unsaved elems of the cache I delete some elems of the cache when the number of elems > sizeObjects R The deletion depends on the check criteria. defaultCheck is the one implemented .dTo drop from the cache all the elems not accesed since half the time between now and the last sync  the default check procedure ? :: Integer -- current time in seconds K -> Integer --last access time for a given object ^ -> Integer --last cache syncronization (with the persisten storage) Y -> Bool --return true for all the elems not accesed since ,half the time between now and the last sync r"  !"#$%&'()*+,-." #$%'&)(+* "!-,.  !"#$%&'),./0123456*return error if any resource is not found 7:;<&the list of resources to be retrieved OThe function that process the resources found and return a Resources structure #The return value in the STM monad. =>?@1  !./0123456789:;<=>?@1  !.45/01236789:;<=>?@/01234567:;<=>?@stuvAwxBfset the cache. this is useful for hot loaded modules that will update an existing cache. Experimental CD6newCache creates a new cache. Experimental ESgetTVars return the TVar that wraps the resources for which the keys are given .  | it return Nothing3 if a TVar with this object has not been allocated M These TVars can be used as usual in explicit user constructed atomic blocks d Additionally, the retrieved TVars remain in the cache and can be accessed and updated by the rest  of the TCache methods.  to keep the consistence in the serialized data, the content of the TVars are written every time the cache is syncronized with the storage until releaseTVars is called $The TVars that contain such objects FlreleaseTVars permits the TVars captured by getTVars to be released. so they can be discarded when not used. H Do this when you no longer need to use them directly in atomic blocks. GpgetTVarsIO does not search for a TVar in the cache like getTVars. Instead of this getTVarsIO creates a list of j TVars with the content given in the list of resourcees and add these TVars to the cache and return them. x the content of the TVars are written every time the cache is syncronized with the storage until releaseTVars is called Hvthis is the main function for the *Resource calls. All the rest derive from it. The results are kept in the STM monad E so it can be part of a larger STM transaction involving other TVars  The J register returned by the user-defined function is interpreted as such: W: additional resources not read in the first parameter of withSTMResources are created/updated with toAdd ,: from the cache and from permanent storage ': will be returned by withSTMResources &the list of resources to be retrieved OThe function that process the resources found and return a Resources structure #The return value in the STM monad. I'update of a single object in the cache "withResource r f= withResources [r] ([mr]-> [f mr])Nprototypes of the object to be retrieved for which keyResource can be derived 0update function that return another full object Jto atomically add/!modify many objects in the cache w withResources rs f= atomically $ withSTMResources rs f1 >> return() where f1 mrs= let as= f mrs in Resources as [] ()K#to read a resource from the cache. getResource r= do{mr<- getResources [r];return $! head mr}LM>delete the resource from cache and from persistent storage. % deleteResource r= deleteResources [r]NEdelete the list of resources from cache and from persistent storage. V deleteResources rs= atomically $ withSTMResources rs f1 where f1 mrs = Resources [] (catMaybes mrs) ()yzOCache handling CStart the thread that clean and writes on the persistent storage. S Otherwise, clearSyncCache must be invoked explicitly or no persistence will exist 5 :: (IResource a) =>Cache a D -> Int --number of seconds betwen checks d -> (Integer-> Integer-> Bool) --The user-defined check-for-cleanup-from-cache for each object C(when this function return True, the object is removed from cache) g -> Int --The max number of objects in the cache, if more, the cleanup start E -> >IO ThreadId --Identifier of the thread created The cache reference (C usually) Inumber of seconds betwen checks. objects not written to disk are written ?The user-defined check-for-cleanup-from-cache for each object. Q is an example EThe max number of objects in the cache, if more, the cleanup starts !Identifier of the thread created PHForce the atomic write of all the cached objects into permanent storage  useful for termination the cache reference ( C usually) {QdTo drop from the cache all the elems not accesed since half the time between now and the last sync g ths is a default cache clearance procedure -- it is invoke when the cache size exceeds the defined in O current time in seconds $last access time for a given object 7last cache syncronization (with the persisten storage) \return true for all the elems not accesed since half the time between now and the last sync |# ABCDEFGHIJKLMNOPQ# EFGHJILKNMABDCPOQABCDEFGHIJKLMNOPQRhandles Dynamic objects using Data.TCache.withResource *withDResource = Data.TCache..withResourceSTvthis is the main function for the *Resource calls. All the rest derive from it. The results are kept in the STM monad E so it can be part of a larger STM transaction involving other TVars  The  ResourcesK register returned by the user-defined function is interpreted as such: toAddW: additional resources not read in the first parameter of withSTMResources are created/updated with toAdd toDelete,: from the cache and from permanent storage toReturn': will be returned by withSTMResources &The list of resources to be retrieved OThe function that process the resources found and return a Resources structure #The return value in the STM monad. U 'getDResource = Data.TCache.getResourceV )getDResources = Data.TCache.getResourcesWSgetTVars return the TVar that wraps the resources for which the keys are given .  | it return Nothing3 if a TVar with this object has not been allocated M These TVars can be used as usual in explicit user constructed atomic blocks d Additionally, the retrieved TVars remain in the cache and can be accessed and updated by the rest  of the TCache methods.  to keep the consistence in the serialized data, the content of the TVars are written every time the cache is syncronized with the storage until releaseTVars is called  See Data.TCache.getTVars XYZ]retrieve a list of objects and return error if any resource is not found. instead of Nothing 2delete a resource from the cache and the storage [:delete a list of resources from the cache and the storage \]CStart the thread that clean and writes on the persistent storage. N Otherwise, syncCache must be invoked explicitly or no persistence will exist Inumber of seconds betwen checks. objects not written to disk are written ?The user-defined check-for-cleanup-from-cache for each object.  defaultCheck is an example EThe max number of objects in the cache, if more, the cleanup starts !Identifier of the thread created ^)methods that handle a single datatype.  similar to Data.TCache.withResource. [ The fact that this method may return a type different that the source type permits to use ' Key' objects _ similar to Data.TCache.withResources. [ The fact that this method may return a type different that the source type permits to use ' Key' objects ` similar to Data.TCache.withSTMResources. O The return in the STM monad permits to participate in larger STM transactions [ The fact that this method may return a type different that the source type permits to use ' Key' objects &the list of resources to be retrieved OThe function that process the resources found and return a Resources structure #The return value in the STM monad. asimilar to Data.TCache.getResource. [ The fact that this method may return a type different that the source type permits to use ' Key' objects b similar to Data.TCache.getResources. [ The fact that this method may return a type different that the source type permits to use ' Key' objects c similar to Data.TCache.deleteResource d similar to Data.TCache.deleteResource 3 ABCQRSTUVWXYZ[\]^_`abcd3 BCQAWXYRSTUVZ[\]^_`abcdRSTUVWXYZ[\]^_`abcd}      !!"#$%&'()*+,-./01234567'(8910*+),-./#$%&:;<)*+,-./01234567:;<8910*+),-./=>?@ABCDEFGHIJKLBCDEFGIJKLM TCache-0.6.5Data.TCache.IResourceData.TCache.TMVarData.TCache.IDynamicData.TCache.TMVar.Dynamic Data.TCacheData.TCache.Dynamic ResourcestoAddtoDeletetoReturnRetry ModifTime AccessTime IResource keyResource serialize deserializetshowptreadpdefPath readResource writeResource delResource resourcesreadFileStrictKeyDynamicInterfacetoIDyn registerTypefromIDynunsafeFromIDyn safeFromIDynIDynamiclistCachesetCacherefcachenewCache getTMVars getTMVarsIOwithSTMResources withResource withResources getResource getResourcesdeleteResourcedeleteResourcesclearSyncCacheProc syncCache defaultCheck withDResourcewithDResourceswithDSTMResources getDResource getDResourcesdeleteDResourcedeleteDResourcesgetTVars releaseTVars getTVarsIOinfinitebase Data.TypeableTypeRephashCheckBlockFlagsMaxTime NoAddToHash AddToHashHtBlock releaseTMVars takeBlocks releaseBlocksclearSyncCachesave