diff --git a/src/data/CCCache.ml b/src/data/CCCache.ml index 3437d493..ec956458 100644 --- a/src/data/CCCache.ml +++ b/src/data/CCCache.ml @@ -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 = diff --git a/src/data/CCCache.mli b/src/data/CCCache.mli index 1caac2ed..e689f090 100644 --- a/src/data/CCCache.mli +++ b/src/data/CCCache.mli @@ -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 *)