https://github.com/html/clache.git
git clone 'https://github.com/html/clache.git'
(ql:quickload :clache)
CLACHE is a general caching library for Common Lisp.
CLACHE provides a general caching facility for Common Lisp. The API is similar with standard hash-table interface. Let me show you an overview of API.
getcache
- Get cache from storagesetcache
- Store cache into storageremcache
- Remove cache from storageclrcache
- Clear all cache in storageAs you can see, it is easy to use. Here is an example:
;; Store cache
(setcache 1 "foo")
;;=> 1
;; Get cache
(getcache 1)
;;=> 1, T
;; Get non-exited cache
(getcache 42)
;;=> NIL, NIL
;; Remove cache
(remcache 1)
;;=> T
;; Clear all cache
(clrcache)
A cache is a triple of a key, a value, and an expiration time.
Any object can be used as a cache key if the object can be converted
into a string properly by using cache-key-to-string
.
Same as cache keys, any object can be used as a cache value. However, a type of cache values can be limited by storages. So you have to be careful what storage are you using.
An expiration time describes how long caches live in seconds. If an
expiration time is nil
, such caches will never be expired:
persistent cache.
If a cache is stored in a storage and has not yet been expired or a persitent cache, we express the cache exists in the storage.
Storage is an abstract layer of maintaining caches. You can access storages via API.
getcache
getcache key &optional storage
Retrieve a cache value from storage
indicated by key
and return
values of the cache value and a boolean whether the cache exists in
storage
. The cache value will be nil
if such the cache doesn't
exist. For example, (getcache "not-existed-cache")
will return nil
,
nil
.
setcache
setcache key value &optional expire storage
Store a cache value
into storage
with key
and expire
. expire
is an expiration time in seconds. If expire
is nil
, the cache will
never be expired. The return value is value
that has been stored.
(setf getcache)
(setf getcache) value key &optional expire storage
Same as setcache
.
remcache
remcache key &optional storage
Remove a cache from storage
indicated by key
. If the cache has
been successfully removed, this function returns t
, otherwise
returns nil
.
clrcache
clrcache &optional storage
Remove all caches from storage
. The return value is undefined.
with-cache
cache
Copyright (C) 2011 Tomohiro Matsuyama <mailto:tomo@cx4a.org>