Feature #272

Updated by Madars about 6 years ago

We could use LMDB for making cache for service calls. The cache could be before tpcall() entry. The cache DB contained following data:
1) Service name,
2) key (format str for UBF for example)
3) partial data to cache (list of UBF field to cache).

Thus if result is found in cache, we return it from cache. The cache settings will be stored in common-config ini file. We shall support different kind of buffers, for UBF we operate with fields (cache storage options: full buffer, or list of fields. In case of list of fields, we merge the call buffer with request buffer), for others that could be regular expression or positions, and storage: full message or specified positions.

There could be api function like tpcachectl(char *db, char *data, long flags), cache driving is handled by @TPCACHENNN (where NNN node id) service. The server could receive ATMI buffer (data) and service name (some field from Exfields) and we need a command code for delete. If fore example for delete command data is empty, then we shall delete all data from DB. Say binary data "tpcachesv", we can run it in multiple copies. The tpcachesv shall subscribe to the event "@CACHEUPDATE" which would process the incoming buffer and store it locally.

The cache rules are processed by cache daemon processes, runt by CMPSRV. The process name "tpcached".

expiry -> drop the cache after the X milliseconds.

<pre>
[@tpcached]
# List of caches to process by daemon (i.e. timeout)
caches=db1,cachesomesvc,cachesomesvc

# Cache files are defined by sub-sections

# Simple cache
[@cachedb/db1]
file=/path/to/some/file1.lmdb

# Time limited cache
[@cachedb/cachesomesvc]
file=/path/to/some/cachesomesv1.lmdb
# milliseconds:
expiry=5000

# Limited slots cache
[@cachedb/cachesomesvc]
file=/path/to/some/limdb.lmdb
# Optional:
limit=1000
# Reset cache file at boot.
flags=bootreset,lru,hits,fifo,expiry
# Notify nodes
# Send nodes 1,4,24 event updates that we have a cache changes.
notifynodes=1,4,23

# lru, hits, fifo -> requires limit. lru,hits,fifo are exclusive, only one should be present

#
# We shall support caches by process sub-sections. so that there could be different caches used by different cctags
#
[@cache]
svc SOMESVC=
{
"caches":[
{
"cachedb":"db1",
"buffer":"UBF",
"keyfmt":"$[T_STRING3]-$[T_STRING4]",
"save":"*",
"rule":"T_FIELD=='CC'"
# If rsprule not present -> Save approved. If present, then evaluate the expression
"rsprule":"EX_TPERRNO==11 && EX_TPURCODE==5"
},
{
"cachedb":"db1",
"buffer":"UBF",
"keyfmt":"$[T_STRING5]-$[T_STRING6]",
"save":"*",
"rule":"T_FIELD=='11'"
},
{
"cachedb":"cachesomesvc",
"buffer":"UBF",
"keyfmt":"$[T_STRING3]-$[T_STRING4]",
"save":"*",
"rule":"T_FIELD=='33'"
}
]
}
</pre>
Also needs to think which process fills up the cache. I would say that this could be client process. So firstly if TPNOCACHE is not set, it check the cache (if initialized), if record not found, cal the server, if answer is succeed, then set up the cache record. We might set it up twice if concurrent calls are running, but I guess this is not a problem.

xadmin command line tool shall allow to drop the cache. The command line interface could look like:

xadmin cachedel -b <db-name> [-k <key_string>] -r [perform regexp match -> loop over all db]

another command we need to show the cache:

xadmin cacheshow [-b <db name>] [-k <key_string>] [-l] [-d] where -d is to show the hex dumps. If not set, then show just infos about number of cached record. -l should list the records with statistics info (last usage date, fifo order)?

Back