mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 19:25:28 -05:00
Merge pull request #156 from Gbury/add-cache
Add `CCCache.add` for manual manipulation of caches
This commit is contained in:
commit
f28b75792b
2 changed files with 14 additions and 0 deletions
|
|
@ -30,6 +30,15 @@ type ('a, 'b) callback = in_cache:bool -> 'a -> 'b -> unit
|
|||
|
||||
let clear c = c.clear ()
|
||||
|
||||
let add c x y =
|
||||
try
|
||||
(* check that x is not bound (see invariants) *)
|
||||
let _ = c.get x in
|
||||
false
|
||||
with Not_found ->
|
||||
c.set x y;
|
||||
true
|
||||
|
||||
let default_callback_ ~in_cache:_ _ _ = ()
|
||||
|
||||
let with_cache ?(cb=default_callback_) c f x =
|
||||
|
|
|
|||
|
|
@ -71,6 +71,11 @@ val size : (_,_) t -> int
|
|||
val iter : ('a,'b) t -> ('a -> 'b -> unit) -> unit
|
||||
(** Iterate on cached values. Should yield [size cache] pairs. *)
|
||||
|
||||
val add : ('a, 'b) t -> 'a -> 'b -> bool
|
||||
(** Manually add a cached value. Returns [true] if the value has succesfully
|
||||
been added, and [false] if the value was already bound.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val dummy : ('a,'b) t
|
||||
(** Dummy cache, never stores any value *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue