diff --git a/private/lru-cache.rkt b/private/lru-cache.rkt index b152052..d88c0d5 100644 --- a/private/lru-cache.rkt +++ b/private/lru-cache.rkt @@ -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 diff --git a/scribblings/lru-cache.scrbl b/scribblings/lru-cache.scrbl index 40aac62..e037ce0 100644 --- a/scribblings/lru-cache.scrbl +++ b/scribblings/lru-cache.scrbl @@ -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)