1cache::async(n) In-memory caches cache::async(n)
2
3
4
5______________________________________________________________________________
6
8 cache::async - Asynchronous in-memory cache
9
11 package require Tcl 8.4
12
13 package require cache::async ?0.3?
14
15 ::cache::async objectName commandprefix ?options...?
16
17 objectName get key donecmdprefix
18
19 objectName set key value
20
21 objectName unset key
22
23 objectName exists key
24
25 objectName clear ?key?
26
27_________________________________________________________________
28
30 This package provides objects which cache data in memory, and operate
31 asynchronously with regard to request and responses. The objects are
32 agnostic with regard to cache keys and values, and unknown methods are
33 delegated to the provider of cached data. These two properties make it
34 easy to use caches as a facade for any data provider.
35
37 The package exports a class, cache::async, as specified below.
38
39 ::cache::async objectName commandprefix ?options...?
40 The command creates a new cache object with an associated global
41 Tcl command whose name is objectName. This command may be used
42 to invoke various operations on the object.
43
44 The commandprefix is the action to perform when an user asks for
45 data in the cache and the cache doesn't yet know about the key.
46 When run the commandprefix is given three additional arguments,
47 the string get, the key requested, and the cache object itself,
48 in the form of its object command, in this order. The execution
49 of the action is done in an idle-handler, decoupling it from the
50 original request.
51
52 The only supported option is
53
54 -full-async-results
55 This option defines the behaviour of the cache for when
56 requested keys are known to the cache at the time of get
57 request. By default such requeste are responded to asyn‐
58 chronously as well. Setting this option to false forces
59 the cache to respond to them synchronuously, although
60 still through the specified callback.
61
62 The object commands created by the class commands above have the form:
63
64 objectName get key donecmdprefix
65 This method requests the data for the key from the cache. If the
66 data is not yet known the command prefix specified during con‐
67 struction of the cache object is used to ask for this informa‐
68 tion.
69
70 Whenever the information is/becomes available the donecmdprefix
71 will be run to transfer the result to the caller. This command
72 prefix is invoked with either 2 or 3 arguments, i.e.
73
74 [1] The string set, the key, and the value.
75
76 [2] The string unset, and the key.
77 These two possibilities are used to either signal the value for the
78 key, or that the key has no value defined for it. The latter is dis‐
79 tinct from the cache not knowing about the key.
80
81 For a cache object configured to be fully asynchronous (default) the
82 donecmdprefix is always run in an idle-handler, decoupling it from the
83 request. Otherwise the callback will be invoked synchronously when the
84 key is known to the cache at the time of the invokation.
85
86 Another important part of the cache's behaviour, as it is asynchronous
87 it is possible that multiple get requests are issued for the same key
88 before it can respond. In that case the cache will issue only one data
89 request to the provider, for the first of these, and suspend the oth‐
90 ers, and then notify all of them when the data becomes available.
91
92 objectName set key value
93
94 objectName unset key
95 These two methods are provided to allow users of the cache to
96 make keys known to the cache, as either having a value, or as
97 undefined.
98
99 It is expected that the data provider (see commandprefix of the
100 constructor) uses them in response to data requests for unknown
101 keys.
102
103 Note how this matches the cache's own API towards its caller,
104 calling the donecmd of get-requests issued to itself with either
105 "set key value" or "unset key", versus issuing get-requests to
106 its own provider with itself in the place of the donecmd,
107 expecting to be called with either "set key value" or "unset
108 key".
109
110 This also means that these methods invoke the donecmd of all
111 get-requests waiting for information about the modified key.
112
113 objectName exists key
114 This method queries the cache for knowledge about the key and
115 returns a boolean value. The result is true if the key is known,
116 and false otherwise.
117
118 objectName clear ?key?
119 This method resets the state of either the specified key or of
120 all keys known to the cache, making it unkown. This forces
121 future get-requests to reload the information from the provider.
122
124 This document, and the package it describes, will undoubtedly contain
125 bugs and other problems. Please report such in the category cache of
126 the Tcllib SF Trackers [http://source‐
127 forge.net/tracker/?group_id=12883]. Please also report any ideas for
128 enhancements you may have for either package and/or documentation.
129
131 asynchronous, cache, callback, synchronous
132
134 Copyright (c) 2008 Andreas Kupries <andreas_kupries@users.sourceforge.net>
135
136
137
138
139cache 0.3 cache::async(n)