File size: 1,537 Bytes
43203b4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | (in-package :clache)
(use-syntax :annot)
#|
Protocol
--------
TODO
|#
@export
(defclass store ()
()
(:documentation "An abstract class of stores. All stores must
inherit from this class."))
(deftype expire ()
"Type for expiration time."
'(or null integer))
@export
(defgeneric load-cache (key store)
(:documentation "Try to retrieve a cache indicated by KEY from STORE
and return values of the cache value and a boolean whether the cache
exists in STORE. The cache value should be NIL if such the cache
doesn't exist or has been expired."))
@export
(defgeneric store-cache (key value store expire)
(:documentation "Store a cache VALUE with KEY into STORE. EXPIRE is
a keep time in seconds. If EXPIRE is NIL, the cache will never
expired. This function should return the value that has been
stored."))
@export
(defgeneric delete-cache (key store)
(:documentation "Remove a cache indicated by KEY from STORE. If the
cache has been successfully removed, this function should return T,
otherwise should return NIL."))
@export
(defgeneric clear-cache (store)
(:documentation "Remove all caches from STORE. Any object can be
returned."))
@export
(defgeneric cache-key-to-string (key)
(:documentation "This function converts any type of KEY into
string. This should be an injective function, meaning this should not
lose the information about key.")
(:method (key) (object-to-string key)))
@export
(defun never-expire-p (expire)
"Return T if EXPIRE represents caches will never be expired."
(eq expire nil))
|