[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Memoizing a procedure
From: |
F. Wittenberger |
Subject: |
Re: [Chicken-users] Memoizing a procedure |
Date: |
Mon, 29 Nov 2010 16:23:49 +0100 |
Am Montag, den 29.11.2010, 10:34 -0300 schrieb Stephen Eilert:
So it is not only "memoization", but a caching system. I was going to
> write something similar, to cache webservice responses.
>
That it is.
I've got several caches working with the attached code.
The API is kind of patterned after SRFI-69.
It tried however to hide that we're using hash tables, since that I
might want to experiment with.
If that fits approximately your needs I'd love to share the code. --
and get your comments (API suggestions anyone?).
(It's not yet available as an egg, though.)
Here's an example which hopefully explains how to use it.
(define *resync-cache*
(make-cache "*resync-cache*"
eq?
#f ;; state
;; miss:
(lambda (cs k) (cons k #f))
;; hit
#f ;; (lambda (c es) #t)
;; fulfil
(lambda (c es results)
(set-cdr! es (if (and (pair? results) (aggregate? (car
results)))
#f
(add-duration
*system-time*
(make-time
'time-duration 0
(or (respond-timeout-interval) 20)))))
(values))
;; valid?
(lambda (es)
(or (not (cdr es))
(srfi19:time<=? *system-time* (cdr es))))
;; delete
#f ;; (lambda (cs es) #f)
))
(cache-ref *resync-cache* oid
(lambda () (%find-frame-sync! oid #f context)))
cache.scm
Description: Text Data