CacheService overview
Table of contents
layers
CacheServiceLive
Live implementation of CacheService.
Creates separate cache instances for each resource type with:
- TTL: 5 minutes
- Capacity: 100 entries per resource type
Signature
export declare const CacheServiceLive: Layer.Layer<CacheService, never, never>
Added in v0.0.1
services
CacheService
Context tag for CacheService.
Signature
export declare const CacheService: Context.Tag<CacheService, CacheService>
Added in v0.0.1
utils
CacheService (interface)
Service that provides per-resource caching for HTTP requests.
Each resource type (users, groups, applications, populations) has its own cache instance with independent TTL and capacity settings.
Signature
export interface CacheService {
/**
* Gets a cached value or computes it if not present.
*
* Only caches GET requests. Other HTTP methods bypass the cache.
* Cache invalidation occurs on POST/PUT/PATCH/DELETE to the same resource.
*
* Cached values are validated at runtime using the provided schema to ensure
* type safety. If validation fails, the cache entry is treated as a miss and
* the value is recomputed.
*
* @param request - The HTTP request to cache
* @param compute - The Effect to compute if cache miss occurs
* @param schema - Schema to validate cached values for type safety
* @returns The cached or computed result
*
* @since 0.0.1
*/
readonly getCached: <A, E, R, SR = never>(
request: HttpClientRequest.HttpClientRequest,
compute: Effect.Effect<A, E, R>,
schema: Schema.Schema<A, any, SR>
) => Effect.Effect<A, E, R | SR>
/**
* Invalidates cache entries for a specific resource type and path.
*
* Called automatically on mutating operations (POST/PUT/PATCH/DELETE).
*
* @param resourceType - The resource type to invalidate
* @param urlPath - The URL path to invalidate
* @returns Effect that completes when invalidation is done
*
* @since 0.0.1
*/
readonly invalidate: (resourceType: ResourceType, urlPath: string) => Effect.Effect<void>
}
Added in v0.0.1
ResourceType (type alias)
Resource types that can be cached.
Signature
export type ResourceType = "users" | "groups" | "applications" | "populations"
Added in v0.0.1