Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add rules/pauljphilp/effectpatterns/add-caching-by-wrapping-a-layergit clone --depth 1 https://github.com/PaulJPhilp/EffectPatternsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/rules/pauljphilp/effectpatterns/add-caching-by-wrapping-a-layer)<a href="https://agentmods.dev/rules/pauljphilp/effectpatterns/add-caching-by-wrapping-a-layer"><img src="https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/add-caching-by-wrapping-a-layer.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00729 | $0.00729 |
| Opus 5 | $0.00365 | $0.00365 |
| Sonnet 5 | $0.00146 | $0.00146 |
| Haiku 4.5 | $0.00073 | $0.00073 |
Grade A, and why
add-caching-by-wrapping-a-layer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 93 lines — stays where its author put it; the contents beside it link to each section on GitHub.
description: Use a wrapping Layer to add cross-cutting concerns like caching to a service without altering its original implementation. globs: "**/*.ts" alwaysApply: true
Add Caching by Wrapping a Layer
Rule: Use a wrapping Layer to add cross-cutting concerns like caching to a service without altering its original implementation.
Example
We have a WeatherService that makes slow API calls. We create a WeatherService.cached wrapper layer that adds an in-memory cache using a Ref and a Map.
import { Effect, Layer, Ref } from "effect";
// 1. Define the service interface
class WeatherService extends Effect.Service<WeatherService>()(
"WeatherService",
{
sync: () => ({
getForecast: (city: string) => Effect.succeed(`Sunny in ${city}`),
}),
}
) {}
// 2. The "Live" implementation that is slow
const WeatherServiceLive = Layer.succeed(
WeatherService,
WeatherService.of({
_tag: "WeatherService",
getForecast: (city) =>
Effect.succeed(`Sunny in ${city}`).pipe(
Effect.delay("2 seconds"),
Effect.tap(() => Effect.log(`Fetched live forecast for ${city}`))
),
})
);
// 3. The Caching Wrapper Layer
const WeatherServiceCached = Layer.effect(
WeatherService,
Effect.gen(function* () {
// It REQUIRES the original WeatherService
const underlyingService = yield* WeatherService;
const cache = yield* Ref.make(new Map<string, string>());
return WeatherService.of({
_tag: "WeatherService",
getForecast: (city) =>
Ref.get(cache).pipe(
Effect.flatMap((map) =>
map.has(city)
? Effect.log(`Cache HIT for ${city}`).pipe(
Effect.as(map.get(city)!)
)
: Effect.log(`Cache MISS for ${city}`).pipe(
Effect.flatMap(() => underlyingService.getForecast(city)),
Effect.tap((forecast) =>
Ref.update(cache, (map) => map.set(city, forecast))
)
)
)
),
});
})
);
// 4. Compose the final layer. The wrapper is provided with the live implementation.
const AppLayer = Layer.provide(WeatherServiceCached, WeatherServiceLive);
// 5. The application logic
const program = Effect.gen(function* () {
const weather = yield* WeatherService;
yield* weather.getForecast("London"); // First call is slow (MISS)
yield* weather.getForecast("London"); // Second call is instant (HIT)
});
Effect.runPromise(Effect.provide(program, AppLayer));
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 4d ago First seen · 93 lines · 729 tokens per session scan A edd47f6570bd
add-caching-by-wrapping-a-layer is a cursor rule published in the GitHub repository PaulJPhilp/EffectPatterns (796 stars, last pushed 2mo ago), licensed MIT. It adds 729 tokens to every session, about $0.0036 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other cursor rules, from other repositories
transcreveai
Required handoff contract for nested TranscreveAI executions.
convex-development---general
Applies general rules for Convex development, emphasizing schema design, validator usage, and correct handling of system fields.
hub-spoke-graph
Hub-and-spoke (MOC) linking for Obsidian vault notes — no peer mesh, leaves up-link only.
langgraph-best-practices
Comprehensive reference for building LangGraph agent workflows including core concepts, graph construction patterns, state management, advanced patterns like Send API and Command, and production-ready code examples.
no-apologies-rule
This rule prevents the AI from using apologies in its responses.
no-summaries-rule
This rule instructs the AI not to summarize changes made.