Module Resource_cache.Make_wrapped
Make a cache from a resource where the type clients wish to operate on is derived from, but not necessarily equal to, the type held by the cache.
Parameters
Signature
val init : config:Config.t -> log_error:(string -> unit) -> common_args -> tval status : t -> Status.tval config : t -> Config.tval with_ : ?open_timeout:Core_kernel.Time_ns.Span.t -> ?give_up:unit Async_kernel.Deferred.t -> t -> key -> f:(resource -> 'a Async_kernel.Deferred.t) -> 'a Async_kernel.Deferred.Or_error.twith_ t key ~fcallsf resourcewhereresourceis either:1) An existing cached resource that was opened with key' such that
R.Key.equal key key'2) A newly opened resource created byR.open_ key common_args, respecting the limits oft.configReturns an error if:
- the cache is closed
R.open_returned an error- no resource is obtained before
give_upis determined
If
fraises, the exception is not caught, but theresourcewill be closed and theCachewill remain in a working state (no resources are lost).
val with_' : ?open_timeout:Core_kernel.Time_ns.Span.t -> ?give_up:unit Async_kernel.Deferred.t -> t -> key -> f:(resource -> 'a Async_kernel.Deferred.t) -> [ `Ok of 'a | `Gave_up_waiting_for_resource | `Error_opening_resource of Core_kernel.Error.t | `Cache_is_closed ] Async_kernel.Deferred.tLike
with_but classify the different errors
val with_any : ?open_timeout:Core_kernel.Time_ns.Span.t -> ?give_up:unit Async_kernel.Deferred.t -> t -> key list -> f:(resource -> 'a Async_kernel.Deferred.t) -> (key * 'a) Async_kernel.Deferred.Or_error.tLike
with_andwith_'exceptfis run on the first matching available resource (or the first resource that has availability to be opened). Preference is given towards those earlier inargs_listwhen possible
val with_any' : ?open_timeout:Core_kernel.Time_ns.Span.t -> ?give_up:unit Async_kernel.Deferred.t -> t -> key list -> f:(resource -> 'a Async_kernel.Deferred.t) -> [ `Ok of key * 'a | `Error_opening_resource of key * Core_kernel.Error.t | `Gave_up_waiting_for_resource | `Cache_is_closed ] Async_kernel.Deferred.tval with_any_loop : ?open_timeout:Core_kernel.Time_ns.Span.t -> ?give_up:unit Async_kernel.Deferred.t -> t -> key list -> f:(resource -> 'a Async_kernel.Deferred.t) -> [ `Ok of key * 'a | `Error_opening_all_resources of (key * Core_kernel.Error.t) list | `Gave_up_waiting_for_resource | `Cache_is_closed ] Async_kernel.Deferred.tTries
with_any'in a loop (removing args that have open errors) until receiving an`Ok, or until it has failed to open all resources inargs_list.
val close_started : t -> boolval close_finished : t -> unit Async_kernel.Deferred.tval close_and_flush : t -> unit Async_kernel.Deferred.tClose all currently open resources and prevent the creation of new ones. All subsequent calls to
with_andimmediatefail with`Cache_is_closed. Any jobs that are waiting for a connection will return with`Cache_is_closed. The returnedDeferred.tis determined when all jobs have finished running and all resources have been closed.