1cache::async(n)                In-memory caches                cache::async(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       cache::async - Asynchronous in-memory cache
9

SYNOPSIS

11       package require Tcl  8.4
12
13       package require cache::async  ?0.3.1?
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

DESCRIPTION

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

API

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
78              These  two possibilities are used to either signal the value for
79              the key, or that the key has no value defined for it. The latter
80              is distinct from the cache not knowing about the key.
81
82              For a cache object configured to be fully asynchronous (default)
83              the donecmdprefix is always run in an  idle-handler,  decoupling
84              it from the request. Otherwise the callback will be invoked syn‐
85              chronously when the key is known to the cache at the time of the
86              invokation.
87
88              Another  important part of the cache's behaviour, as it is asyn‐
89              chronous it is possible that multiple get  requests  are  issued
90              for  the  same key before it can respond. In that case the cache
91              will issue only one data request to the provider, for the  first
92              of  these,  and  suspend the others, and then notify all of them
93              when the data becomes available.
94
95       objectName set key value
96
97       objectName unset key
98              These two methods are provided to allow users of  the  cache  to
99              make  keys  known  to the cache, as either having a value, or as
100              undefined.
101
102              It is expected that the data provider (see commandprefix of  the
103              constructor)  uses them in response to data requests for unknown
104              keys.
105
106              Note how this matches the cache's own API  towards  its  caller,
107              calling the donecmd of get-requests issued to itself with either
108              "set key value" or "unset key", versus issuing  get-requests  to
109              its  own  provider  with itself in the place of the donecmd, ex‐
110              pecting to be called with either "set key value" or "unset key".
111
112              This also means that these methods invoke  the  donecmd  of  all
113              get-requests waiting for information about the modified key.
114
115       objectName exists key
116              This  method  queries  the cache for knowledge about the key and
117              returns a boolean value. The result is true if the key is known,
118              and false otherwise.
119
120       objectName clear ?key?
121              This  method  resets the state of either the specified key or of
122              all keys known to the cache, making it unkown. This  forces  fu‐
123              ture get-requests to reload the information from the provider.
124

BUGS, IDEAS, FEEDBACK

126       This  document,  and the package it describes, will undoubtedly contain
127       bugs and other problems.  Please report such in the category  cache  of
128       the  Tcllib  Trackers  [http://core.tcl.tk/tcllib/reportlist].   Please
129       also report any ideas for enhancements you may have for either  package
130       and/or documentation.
131
132       When proposing code changes, please provide unified diffs, i.e the out‐
133       put of diff -u.
134
135       Note further that  attachments  are  strongly  preferred  over  inlined
136       patches.  Attachments  can  be  made  by  going to the Edit form of the
137       ticket immediately after its creation, and  then  using  the  left-most
138       button in the secondary navigation bar.
139

KEYWORDS

141       asynchronous, cache, callback, synchronous
142
144       Copyright (c) 2008 Andreas Kupries <andreas_kupries@users.sourceforge.net>
145
146
147
148
149tcllib                               0.3.1                     cache::async(n)
Impressum