h&MHT      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                            Safe-Inferred "68TCachecheck if a (possibly polimorphic) value within a IDynamic value has the given serialization"    Safe-Inferred6 2 TCache=a persist mechanism has to implement these three primitives 3 is the default file persistenceTCacheread by key. It must be strictTCachewrite. It must be strictTCachedeleteTCache-Used by IndexQuery for index persistence(see Data.TCache.IndexQuery.TCacheSerialize 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 9 serialize = pack . show deserialize= read . unpackSince write and read to disk of to/from the cache are not be very frequent The performance of serialization is not critical.$TCacheIndexable is an utility class used to derive instances of IResourceExample: 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  ans , by defining the $ 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 3TCacheImplements default default-persistence of objects in files with their keys as filenames5TCache-Set the default persistence mechanism of all  serializable objects that have setPersist= const Nothing. By default it is 3this statement must be the first one before any other TCache call?TCache:Strict read from file, needed for default file persistence#TCachedefaultPersist if Nothing&TCacheadditional extension for default file paths. IMPORTANT: defPath must depend on the datatype, not the value (must be constant). Default is ".tcachedata/")#"! $&%'()*+,/.-0123456789:;<=>?)10,/.-*+)'(2$&%#"! 3456789:;<=>? Safe-Inferred GTCache"Resources data definition used by withSTMResourcesHTCacheforces a retryJTCache*resources to be inserted back in the cacheKTCacheresources to be deleted from the cache and from permanent storageLTCacheresult to be returnedMTCache.Must be defined for every object to be cached.OTCacheImplements 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  safeIOToSTM8 it is guaranteed that the execution is not interrupted.PTCache0hopefully optimized read of many objects by key.RTCacheTo 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, R must retry until success.STCachemultiple write (hopefully) in a single request. That is up to you and your backend . Defined by default as 'mapM_ writeResource'TTCacheDelete the resource. It is called syncronously. So it must commitVTCacheEmpty resources: resources= Resources [] [] ()NTCachemust be definedGLKJHIMUTSRQPONVMUTSRQPONGLKJHIV Safe-Inferred6 WTCacheAdd an user defined trigger to the list of triggers Trriggers are called just before an object of the given type is created, modified or deleted. The DBRef to the object and the new value is passed to the trigger. The called trigger function has two parameters: the DBRef being accesed (which still contains the old value), and the new value. If the DBRef is being deleted, the second parameter is . if the DBRef contains Nothing, then the object is being createdXTCache*internally called when a DBRef is modifieddeletedcreated '(*+,-./WX '(*+,-./WX Safe-Inferred83%ZTCache%sync state to permanent storage when { is invoked\TCacheuse y to write the state]TCache1number of seconds between saves when asynchronous^TCache?The user-defined check-for-cleanup-from-cache for each object. } is an example_TCachesize of the cache when asyncaTCacheSet the cache. this is useful for hot loaded modules that will update an existing cache. ExperimentalTCache(The cache holder. established by defaultbTCache!Creates a new cache. ExperimentalcTCacheReturn the total number of DBRefs in the cache. For debug purposes. This does not count the number of objects in the cache since many of the '8s may not have the referenced object loaded. It's O(n).dTCacheRetuns some statistical information for the DBRefs in the cache (for debugging) This returns a tuple containing: total : count of the total elements in cache dirty : the elements which need to be written to the persistent storage loaded : the elements which are currently hold in memoryeTCacheReturn the reference value. If it is not in the cache, it is fetched from the database.fTCache7Read multiple DBRefs in a single request using the new PgTCacheWrite in the reference a value The new key must be the same than the old key of the previous object stored otherwise, an error "law of key conservation broken" will be raisedWARNING: the value to be written in the DBRef must be fully evaluated. Delayed evaluations at serialization time can cause inconsistencies in the database. In future releases this will be enforced.hTCache4Return the key of the object referenced by the DBRefiTCacheGet the reference to the object in the cache. If it does not exist, the reference is created empty. Every execution of i returns the same unique reference to this key, so it can be safely considered pure. This property is useful because deserialization of objects with unused embedded 's do not need to marshall them eagerly. This also avoids unnecessary cache lookups of the referenced objects.jTCacheCreate the object passed as parameter (if it does not exist) and -- return its reference in the IO monad. -- If an object with the same key already exists, it is returned as is -- If not, the reference is created with the new value. -- If you like to update in any case, use i and g combined newDBRefIO :: (IResource a,Typeable a) => a -> IO (DBRef a) newDBRefIO x= do let key = keyResource x mdbref <- mDBRefIO key case mdbref of Right dbref -> return dbrefLeft cache -> do tv<- newTVarIO DoNotExist let dbref= DBRef key tv w <- mkWeakPtr dbref . Just $ fixToCache dbref H.insert cache key (CacheElem Nothing w) t <- timeInteger atomically $ do applyTriggers [dbref] [Just x] --debug ("before "++key) writeTVar tv . Exist $ Elem x t t return dbrefCreate the object passed as parameter (if it does not exist) and return its reference in the STM monad. If an object with the same key already exists, it is returned as is If not, the reference is created with the new value. If you like to update in any case, use i and g combined if you need to create the reference and the reference content, use jkTCacheDelete the content of the DBRef form the cache and from permanent storagelTCacheHandles Nothing cases in a simpler way than runMaybeT. it is used in infix notation. for example: result <- readDBRef ref `onNothing` error ("Not found "++ keyObjDBRef ref)or ;result <- readDBRef ref `onNothing` return someDefaultValuemTCacheDeletes the referenced object from the cache, not the database (see k) useful for cache invalidation when the database is modified by other processes.nTCache$flush the element with the given keyoTCache,label the object as not existent in databasepTCachedrops the entire cache.qTCacheThis is the main function for the *Resource(s) calls. All the rest derive from it. The results are kept in the STM monad so it can be part of a larger STM transaction involving other DBRefs. The G register returned by the user-defined function is interpreted as such:J?: the content of this field will be added/updated to the cacheK: the content of this field will be removed from the cache and from permanent storageL0: the content of this field will be returned by qWARNING: To catch evaluations errors at the right place, the values to be written must be fully evaluated. Errors in delayed evaluations at serialization time can cause inconsistencies in the database.rTCache&Update of a single object in the cache withResource r f= s [r] ([mr]-> [f mr])sTCache2To atomically add/modify many objects in the cache # withResources rs f= atomically $ q rs f1 >> return() where f1 mrs= let as= f mrs in Resources as [] ()tTCache"To read a resource from the cache. getResource r= do{mr<- u [r];return $! head mr}uTCache8To read a list of resources from the cache if they exist| getResources rs= atomically $ q* rs f1 where f1 mrs= Resources [] [] mrsvTCache=Delete the resource from cache and from persistent storage.  deleteResource r= w [r]wTCacheDelete the list of resources from cache and from persistent storage. # deleteResources rs= atomically $ q7 rs f1 where f1 mrs = Resources [] (catMaybes mrs) ()xTCache(Start the thread that periodically call | to clean and writes on the persistent storage. it is indirectly set by means of z, since it is more higuer level. I recommend to use the latter Otherwise, y or | or { must be invoked explicitly or no persistence will exist. Cache writes allways save a coherent stateyTCacheForce the atomic write of all cached objects modified since the last save into permanent storage. Cache writes allways save a coherent state. As always, only the modified objects are written.zTCacheSpecify the cache synchronization policy with permanent storage. See Y for details{TCachePerform a synchronization of the cache with permanent storage once executed the STM transaction when z policy is Z|TCacheSaves the unsaved elems of the cache. Cache writes allways save a coherent state. Unlike y this call deletes some elems from the cache when the number of elems >  sizeObjects. The deletion depends on the check criteria, expressed by the first parameter. } is the one implemented to be passed by default. Look at it to understand the clearing criteria.}TCacheThis is a default cache clearance check. It forces to drop from the cache all the elems not accesed since half the time between now and the last sync if it returns True, the object will be discarded from the cache it is invoked when the cache size exceeds the number of objects configured in x or |~TCache?stablishes the procedures to call before and after saving with y, | or x. The postcondition of database persistence should be a commit.TCacheAssures that the IO computation finalizes no matter if the STM transaction is aborted or retried. The IO computation run in a different thread. The STM transaction wait until the completion of the IO procedure (or retry as usual).It can be retried if the embedding STM computation is retried so the IO computation must be idempotent. Exceptions are bubbled up to the STM transactionqTCache%the list of resources to be retrievedTCacheThe function that process the resources found and return a Resources structureTCache"The return value in the STM monad.xTCachenumber of seconds betwen checks. objects not written to disk are writtenTCache?The user-defined check-for-cleanup-from-cache for each object. } is an exampleTCacheThe max number of objects in the cache, if more, the cleanup startsTCache Identifier of the thread created}TCachecurrent time in secondsTCache#last access time for a given objectTCache7last cache synchronization (with the persisten storage)TCachereturn true for all the elems not accesed since half the time between now and the last sync<'GIHJKLMNOPQRSTUVWYZ[\^]_`abcdefghijklmnopqrstuvwxyz{|}~<{'ihjefgkMNOPQRSTUGIHJKLVqsrutwvWmnop`aby~|cdzYZ[\^]_x}l Safe-Inferred6;TCache:to execute a monad for the purpose of memoizing its resultTCachegiven a string, return a key that can be used in Indexable instances Of non persistent objects, such are cached objects (it changes fron execution to execution) . It uses TCachememoize the result of a computation for a certain time. This is useful for caching costly data such web pages composed on the fly.time == 0 means infiniteTCacheMemoize the result of a computation for a certain time. A string % is used to index the resultThe Int parameter is the timeout, in second after the last evaluation, after which the cached value will be discarded and the expression will be evaluated again if demanded . Time == 0 means no timeoutTCachea pure version of cached Safe-Inferred 6=TCacheimplement the relational-like operators, operating on record fieldsTCacheRegister a trigger for indexing the values of the field passed as parameter. the indexed field can be used to perform relational-like searchesTCachereturn all the (indexed) values which this field has and a DBRef pointer to the register  3455555 Safe-Inferred6B(TCache9start a trigger to index the contents of a register fieldTCachetrigger the indexation of list fields with elements convertible to TextTCachereturn the DBRefs of the registers whose field (first parameter, usually a container) contains the requested value.TCachereturn all the values of a given field (if it has been indexed with )TCachereturn the DBRefs whose fields include all the words in the requested text contents.Except the words with less than three characters that are not digits or uppercase, that are filtered out before making the queryTCachefield to indexTCache>method to convert the field content to lazy Text (for example  in case of String fields). This permits to index non Textual fieldsTCachefield to indexTCachemethod to convert a field element to Text (for example `pack . show` in case of elemets with Show instances)TCachefield to search inTCachetext to search  Safe-InferredBTCacheBy default the index of a  data persist with the data. !"#$%&356$%& !"#563  Safe-Inferred "6GTCacheA queue referenceTCache'push an element at the top of the queueTCacheCheck if the queue is emptyTCache:Get the reference to new or existing queue trough its nameTCache*Empty the queue (factually, it is deleted)TCacheVersion in the STM monadTCache8Read the first element in the queue and delete it (pop)TCacheVersion in the STM monadTCachePush an element in the queueTCacheVersion in the STM monadTCacheReturn the list of all elements in the queue. The queue remains unchangedTCacheVersion in the STM monadTCache?@ABCDEFGHIJKLMNOPQRQSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                      $TCache-0.13.3-AbqkwodcBqVHdCsrmZuAJh Data.TCacheData.Persistent.IDynamicData.TCache.DefsData.TCache.IResourceData.TCache.TriggersData.TCache.MemoizationData.TCache.IndexQueryData.TCache.IndexTextData.TCache.DefaultPersistenceData.Persistent.Collection Paths_TCachebase GHC.Conc.SyncSTM unsafeIOToSTM atomicallySaveIDynTypeDRightDLeftIDynamicIDyntosave errorfied dynPrefix dynPrefixSp notreifiedtoIDynserializedEqualfromIDyn safeFromIDynreifyM$fShowIDynamic$fSerializeIDynamic$fSerializeSavePersist readByKeywritedeleteKey PersistIndex persistIndex Serializable serialize deserialize deserialKey setPersist IndexablekeydefPathDBRefTPVarElemStatusNotRead DoNotExistExist ModifTime AccessTimecastErr filePersistdefaultPersistIORefsetDefaultPersistgetDefaultPersist getPersistdefaultReadByKey defaultWrite safeWrite defaultDeletedefReadResourceByKeydefWriteResourcedefDelResourcereadFileStrict $fOrdDBRef $fEqDBRef $fShowDBRef $fIndexable()$fIndexableInteger$fIndexableInt $fIndexable[] ResourcesRetrytoAddtoDeletetoReturn IResource keyResourcereadResourceByKeyreadResourcesByKey readResource writeResourcewriteResources delResource delResources resources addTrigger applyTriggersSyncMode Synchronous Asynchronous SyncManual frequencycheck cacheSizeCachesetCachenewCachenumElems statElems readDBRef readDBRefs writeDBRef keyObjDBRefgetDBRefnewDBRefdelDBRef onNothing flushDBRefflushKey invalidateKeyflushAllwithSTMResources withResource withResources getResource getResourcesdeleteResourcedeleteResourcesclearSyncCacheProc syncCache syncWriteatomicallySyncclearSyncCache defaultCheck setConditions safeIOToSTM $fReadDBRef ExecutableexecuteaddrStr writeCached cachedByKeycachedByKeySTM flushCachedcachedp$fMonadIOIdentity$fExecutableIdentity$fExecutableIO$fIResourceCachedselect.||..&&..==..>..>=..<=..<. QueriableindexindexOf recordsWith$fQueriablerega$fIndexableIndex$fSerializableIndex $fReadIndex$fIResourceIndex$fRelationOpsFUNa[]$fRelationOpsFUNFUN[]$fSetOperations[][][]$fSetOperations[][][]0$fSetOperations[][][]1$fSetOperations[][][]2$fSelect(,)STMSTM$fSelect(,,,)STMSTM$fSelect(,,)STMSTM$fSelect(,)STMSTM0$fSelectFUNSTMSTM $fShowIndex indexText indexList containsElem allElemsOfcontains$fIResourceIndexText$fIndexableIndexText$fSerializableIndexText$fReadIndexText$fShowIndexText$fPersistIndexa $fIResourceaRefQueue unreadSTMisEmpty isEmptySTMgetQRefflushflushSTMpoppopSTMpickpushpushSTMpickAll pickAllSTMpickElem pickElemSTM updateElem updateElemSTMreadAll readAllSTM deleteElem deleteElemSTM$fSerializableQueue$fSerializeQueue$fIndexableQueueGHC.ReadReadGHC.ShowShow GHC.MaybeNothingrefcache)RefSerialize-0.4.0-9CRHunPke9WALYvQ5MVqIKData.RefSerialize.SerializeaddrHash RelationOpsbytestring-0.11.3.1Data.ByteString.Lazy.Char8packversiongetDataFileName getBinDir getLibDir getDynLibDir getDataDir getLibexecDir getSysconfDir