Effect CommunityEC
Effect Community•3y ago•
20 replies
Sly

Confusing Description of AppLayer with Conditional Caching and Effect Operation

I'm looking for guidance and already apologize if the description is going to be bit confusing 😉 :

In my application, I'm constructing an AppLayer using Layer.provideMerge by merging various different layers. One of these layers provides a caching service, and it's chosen conditionally based on the information available at startup.

This caching layer is created using Layer.scoped and includes an Effect.acquireRelease operation. It appears that this layer's lifetime is correlated to the Effect.runPromiseEither the AppLayer is provided to via Effect.provideLayer. On the other hand, the buildup of the AppLayer only occurs once (atleast a breakpoint set within it is not triggered multiple times).

What I'm looking to understand is if there's a way for me to assign a different scope to this caching layer. Ideally, I would like to avoid the acquisition and release of the layer during each Effect.runPromiseEither call (which I ?need? to do for basically every API call to my service due to the frameworks buildup right now). Instead, I would prefer these operations to occur over the lifetime of an externally provided scope (so e.g. the Scope of that AppLayer, if that makes any sense).

Any idea how I would do that?
Was this page helpful?