Skip to content

Instantly share code, notes, and snippets.

@cranst0n
cranst0n / CachedResource-Blog.md
Created March 26, 2024 17:19 — forked from Daenyth/CachedResource-Blog.md
CachedResource for cats-effect

Concurrent resource caching for cats

Motivation

cats-effect Resource is extremely handy for managing the lifecycle of stateful resources, for example database or queue connections. It gives a main interface of:

trait Resource[F[_], A] {
  /** - Acquire resource
    * - Run f
 * - guarantee that if acquire ran, release will run, even if `use` is cancelled or `f` fails