-
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
lru-has?
|
||||
lru-add!
|
||||
lru-count
|
||||
lru-empty?
|
||||
lru->list
|
||||
lru-clear
|
||||
)
|
||||
@@ -155,6 +156,10 @@
|
||||
)
|
||||
)
|
||||
|
||||
(define/contract (lru-empty? l)
|
||||
(-> lru*? boolean?)
|
||||
(= (lru-count l) 0))
|
||||
|
||||
(define/contract (lru-count lru)
|
||||
(-> lru*? larger-equal0?)
|
||||
(with-lock lru
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
@(require scribble/example)
|
||||
|
||||
@title{LRU Cache (Least Recently Used) for Racket}
|
||||
@author{You}
|
||||
@author[@author+email["Hans Dijkema" "hans@dijkewijk.nl"]]
|
||||
|
||||
@defmodule[lru-cache]{
|
||||
An in-memory LRU cache with optional item expiration. The cache keeps items in
|
||||
@@ -87,6 +87,10 @@ Clear all items from the cache. Returns @racket[l].
|
||||
Return the number of @emph{non-expired} items currently in the cache.
|
||||
}
|
||||
|
||||
@defproc[(lru-empty? [l lru?]) boolean?]{
|
||||
Return @emph{#t} if the number of @emph{non-expired} items currently in the cache equals 0.
|
||||
}
|
||||
|
||||
@defproc[(lru->list [l lru?] [#:with-expire with-expire? boolean? #f]) list?]{
|
||||
Return the cache contents in recency order (most recent first).
|
||||
When @racket[with-expire?] is @racket[#f] (default), returns just the list of items.
|
||||
@@ -120,12 +124,11 @@ a positive integer), otherwise @racket[#f].
|
||||
|
||||
@section{Examples}
|
||||
|
||||
@examples[
|
||||
#:eval (make-base-eval)
|
||||
@#reader scribble/comment-reader
|
||||
[racketblock
|
||||
(require racket/base)
|
||||
|
||||
;; Assuming your module is "lru.rkt" next to this file:
|
||||
(require "../private/lru-cache.rkt")
|
||||
(require lru-cache)
|
||||
|
||||
(define L (make-lru 3)) ;; max 3 items, no expiration
|
||||
(lru-add! L 'a)
|
||||
|
||||
Reference in New Issue
Block a user