Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file resource_cache_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155open!Core_kernelopen!Async_kernelopen!ImportmoduletypeS=sigtypekeytypecommon_argstyperesourcemoduleStatus:Status.SwithtypeKey.t=keytypetvalinit:config:Config.t->log_error:(string->unit)->common_args->tvalstatus:t->Status.tvalconfig:t->Config.t(** [with_ t key ~f] calls [f resource] where [resource] is either:
1) An existing cached resource that was opened with key' such that
[R.Key.equal key key']
2) A newly opened resource created by [R.open_ key common_args], respecting
the limits of [t.config]
Returns an error if:
- the cache is closed
- [R.open_] returned an error
- no resource is obtained before [give_up] is determined
If [f] raises, the exception is not caught, but the [resource] will be
closed and the [Cache] will remain in a working state (no resources are lost). *)valwith_:?open_timeout:Time_ns.Span.t(** default [None] *)->?give_up:unitDeferred.t(** default [Deferred.never] *)->t->key->f:(resource->'aDeferred.t)->'aDeferred.Or_error.t(** Like [with_] but classify the different errors *)valwith_':?open_timeout:Time_ns.Span.t->?give_up:unitDeferred.t->t->key->f:(resource->'aDeferred.t)->[`Okof'a|`Gave_up_waiting_for_resource|`Error_opening_resourceofError.t|`Cache_is_closed]Deferred.t(** Like [with_] and [with_'] except [f] is run on the first matching available resource
(or the first resource that has availability to be opened).
Preference is given towards resources earlier in the list, unless
[~load_balance:true] has been specified, in which case preference is given to ensure
that load is approximately balanced. The key with the least number of open
connections will be favored. *)valwith_any:?open_timeout:Time_ns.Span.t->?give_up:unitDeferred.t->?load_balance:bool->t->keylist->f:(resource->'aDeferred.t)->(key*'a)Deferred.Or_error.tvalwith_any':?open_timeout:Time_ns.Span.t->?give_up:unitDeferred.t->?load_balance:bool->t->keylist->f:(resource->'aDeferred.t)->[`Okofkey*'a|`Error_opening_resourceofkey*Error.t|`Gave_up_waiting_for_resource|`Cache_is_closed]Deferred.t(** Tries [with_any'] in a loop (removing args that have open errors) until receiving an
[`Ok], or until it has failed to open all resources in [args_list]. *)valwith_any_loop:?open_timeout:Time_ns.Span.t->?give_up:unitDeferred.t->?load_balance:bool->t->keylist->f:(resource->'aDeferred.t)->[`Okofkey*'a|`Error_opening_all_resourcesof(key*Error.t)list|`Gave_up_waiting_for_resource|`Cache_is_closed]Deferred.tvalclose_started:t->boolvalclose_finished:t->unitDeferred.t(** Close all currently open resources and prevent the creation of new ones. All
subsequent calls to [with_] and [immediate] fail with [`Cache_is_closed]. Any jobs
that are waiting for a connection will return with [`Cache_is_closed]. The
returned [Deferred.t] is determined when all jobs have finished running and all
resources have been closed. *)valclose_and_flush:t->unitDeferred.tendmoduletypeResource_cache=sigmoduletypeS=S(** [Cache.Make] creates a cache module that exposes a simple [with_] interface over its
resources. The cache has the following properties:
Resource reuse: When a resource [r] is opened, it will remain open until one of the
following:
- [f r] raised an exception where [f] was a function passed to [with_]
- [r] has been idle for [idle_cleanup_after]
- [r] has been used [max_resource_reuse] times
- [close_and_flush] has been called on the cache
When a resource is closed, either because of one of the above conditions, or because
it was closed by other means, it no longer counts towards the limits.
Limits: The cache respects the following limits:
- No more than [max_resources] are open simultaneously
- No more than [max_resources_per_id] are open simultaneously for a given id (args)
*)moduleMake(R:Resource.S)():Swithtypekey:=R.Key.tandtypecommon_args:=R.Common_args.tandtyperesource:=R.t(** Wrap a resource that does not natively support a [has_close_started] operation
in a simple record to add such tracking. *)moduleMake_simple(R:Resource.Simple)():Swithtypekey:=R.Key.tandtypecommon_args:=R.Common_args.tandtyperesource:=R.t(** 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. *)moduleMake_wrapped(R:Resource.S_wrapped)():Swithtypekey:=R.Key.tandtypecommon_args:=R.Common_args.tandtyperesource:=R.resourceend