add-caching-by-wrapping-a-layer

add-caching-by-wrapping-a-layer is a cursor rule for Cursor from PaulJPhilp/EffectPatterns. It costs 729 tokens per session, scanned A, original, MIT.

A TypeScript pattern for adding an in-memory cache around a service without changing the service itself.

In plain words
What is it for?
Use it to cache results from services such as a weather API by wrapping their service layer with a Ref and Map.
Why use it?
It avoids repeating slow work, while keeping the original service implementation separate from the caching logic.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it to cache results from services such as a weather API by wrapping their service layer with a Ref and Map.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/pauljphilp/effectpatterns/add-caching-by-wrapping-a-layer
Install

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.

Clone the repo
git clone --depth 1 https://github.com/PaulJPhilp/EffectPatterns

Made for: Cursor.

Wrote 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.

agentmods badge for add-caching-by-wrapping-a-layer

README.md
[![agentmods](https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/add-caching-by-wrapping-a-layer/github.svg)](https://agentmods.dev/rules/pauljphilp/effectpatterns/add-caching-by-wrapping-a-layer)
Your own site
<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/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for add-caching-by-wrapping-a-layer

Your own site · 80×15
<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="Reviewed on agentmods" width="80" height="20"></a>
Per session 729 This file is loaded in full into every session.
When invoked 729 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce invoked
Fable 5.1 $0.00729 $0.00729
Opus 5.5 $0.00292 $0.00292
Sonnet 5.5 $0.00146 $0.00146
Haiku 4.5 $0.00073 $0.00073

Measured 3mo ago against content hash edd47f6570bd, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

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 3mo 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.

content/published/rules/cursor/add-caching-by-wrapping-a-layer.mdc · 93 lines

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));

Read the full file on GitHub · 93 lines

Changes

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.

  1. 3mo ago First seen · 93 lines · 729 tokens per session scan A edd47f6570bd

Subscribe to this mod's changes

add-caching-by-wrapping-a-layer is a cursor rule published in the GitHub repository PaulJPhilp/EffectPatterns (807 stars, last pushed 5mo ago), licensed MIT. It adds 729 tokens to every session, about $0.0029 per session on Opus 5.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.

Related

add-caching-by-wrapping-a-layer compared with cursor rules from other repositories

add-caching-by-wrapping-a-layer next to 6 cursor rules from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
add-caching-by-wrapping-a-layerPaulJPhilp/EffectPatternsCursor rule8075mo agoMITA729Cursor
spring-boot-redislsampaioweb/ai-instructionsCursor rule110d agoMITA0Cursor
django-orm-for-database-operationsWebDevPeterGriffin/The-VibeCode-BibleCursor rule4226d agononeA48Cursor
nosql-specialist-intelligentshahshrey/cursor-hubCursor rule1520d agononeA150Cursor
caching-managementhhx465453939/mcp-pubmed-serverCursor rule69mo agoApache-2.0A0Cursor
canonical__eedisBilal140202/the-lord-of-the-skillsCursor rule62mo agoMITA468Cursor
ponytailDietrichGebert/ponytailCursor rule201k8d agoMITA604Cursor