Merge pull request #156 from Gbury/add-cache

Add `CCCache.add` for manual manipulation of caches
This commit is contained in:
Simon Cruanes 2017-11-01 17:32:40 +01:00 committed by GitHub
commit f28b75792b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -30,6 +30,15 @@ type ('a, 'b) callback = in_cache:bool -> 'a -> 'b -> unit
let clear c = c.clear () 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 default_callback_ ~in_cache:_ _ _ = ()
let with_cache ?(cb=default_callback_) c f x = let with_cache ?(cb=default_callback_) c f x =

View file

@ -71,6 +71,11 @@ val size : (_,_) t -> int
val iter : ('a,'b) t -> ('a -> 'b -> unit) -> unit val iter : ('a,'b) t -> ('a -> 'b -> unit) -> unit
(** Iterate on cached values. Should yield [size cache] pairs. *) (** 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 val dummy : ('a,'b) t
(** Dummy cache, never stores any value *) (** Dummy cache, never stores any value *)