package weberizer

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Weberizer.CacheSource

Simple cache with dependencies and timeout.

Sourcetype 'a t

A cache for elements of type 'a.

Sourceval make : ?dep:'b t -> ?new_if:('a t -> bool) -> ?timeout:float -> ?debug:bool -> string -> ('a option -> 'a) -> 'a t

make key f create a new cache to hold the return value of f using the key. f is given its previously returned value if any — it may be less work to update it than recreating it afresh. The disk cache will be updated when the program exits, so its content will persist across multiplie runs of the program. The type 'a must be marshal-able.

  • parameter timeout

    the number of seconds after which the cached value must be refreshed (running f again). Default: 3600.. A non-positive value means no timeout.

  • parameter debug

    print messages on stderr about cache usage and refresh. The string argument is a prefix to these messages to be able to distinguish different caches. Default: "" i.e., no messages.

Sourceval update : ?f:('a option -> 'a) -> 'a t -> unit

update t update the cache immediately. If f is given, first set the function generating values for the cache t to f and then update the cache by running f.

Sourceval depend : 'a t -> dep:'b t -> unit

depend t t' says that the cache t depends on the cache t' i.e. that before updating t, one must update t'.

Sourceval get : ?update:bool -> 'a t -> 'a

Get the value stored in the cache. This operation will update the cached value if necessary.

  • parameter update

    if true, force an update. Default: false.

Sourceval result : ?dep:'b t -> ?new_if:('a t -> bool) -> ?timeout:float -> ?debug:bool -> string -> ('a option -> 'a) -> 'a

result key f is a convenience function equivalent to get(make key f).

Sourceval time : 'a t -> float

The time of the last update of the cache. Returns neg_infinity if the cache is not initialized.

Sourceval key : 'a t -> string

key t returns the key used to store the value.

OCaml

Innovation. Community. Security.