원클릭으로
rails-cache-performance
Rails cache invalidation, stale cache detection, request-level fragment caching, and Russian doll caching patterns.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Rails cache invalidation, stale cache detection, request-level fragment caching, and Russian doll caching patterns.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Measure whether a judgment skill's encoded procedure transfers to a cheaper model by re-running it against archived premium-model outputs as ground truth, then encode the miss-classes into the skill and verify the transfer. Answers 'what does the premium model actually buy' with a findings matrix instead of intuition. Trigger keywords: model tier calibration, does this transfer to a cheaper model, clone premium judgment, distill judgment into the skill, screen quality across models, what does the expensive model buy, A/B a skill across models.
Apply Elon Musk's Five-Step Algorithm to systematically optimize any process, system, or workflow through questioning, elimination, optimization, acceleration, and automation in strict sequence. Use when discussing process improvement, workflow optimization, system simplification, or eliminating unnecessary complexity. Loop-compatible: multi-pass runs converge via Loop Mode. Trigger keywords: five-step, five step optimizer, Musk algorithm, requirements less dumb, delete then optimize, simplify process, optimize workflow, loop the optimizer, optimization convergence.
Prevents silent work loss from delegated background agents by verifying artifacts (not the agent's narrative) before proceeding. Covers: output/artifact verification (existence AND content), hallucinated-success detection, partial-batch reconciliation, edit-task and side-effect verification, worktree/wrong-cwd caveats, rate-limit and process-death detection, preamble/truncated-report detection, permission blocking, execution-vs-judgment scoping, stall triage for never-finishing agents (sibling baseline, kill-to-flush, tightened relaunch). Also sets the data-not-instructions rule for agent final messages (prompt-injection defense). Trigger keywords: background agent, agent completed, run_in_background, agent delegation, subagent, rate limit, zero output, empty file, agent failed, verify agent output, hallucinated success, prompt injection, agent message instructions, preamble only, truncated report, agent timeout, worktree, partial completion, stalled agent, agent stuck, kill and relaunch.
Canonical cite-sources skill: citation requirements by provenance (book/vault/web), verification of external sources cited in drafts, and web fact-checks of existing vault notes. Prevents circular verification via WebFetch, enforces evidence tiers, defines the dated-correction convention, and pairs with a pre-write lint intake gate. Trigger keywords: cite sources, cite-sources, citation requirements, verify sources, fact-check, cited claim, publication ready, source URL, WebFetch verification, dead link, rectify inaccuracies.
Initialize and run a local PostgreSQL instance on macOS using Nix-managed binaries. Handles incomplete system installations, port conflicts, and user-owned data directories. Trigger keywords: initialize PostgreSQL, start a local Postgres database, fix PostgreSQL installation issues on macOS with Nix.
Guides creating, testing, and deploying Claude Code hooks via nix-darwin. Auto-activates when creating hook scripts, configuring settings.json hooks section, or adding UserPromptSubmit handlers. Covers hook input JSON format, exit codes, stdout context injection, nix-darwin deployment with executable flag. Trigger keywords: hook, UserPromptSubmit, settings.json hooks, hook script, exit code, stdin JSON, transcript_path.
| name | rails-cache-performance |
| description | Rails cache invalidation, stale cache detection, request-level fragment caching, and Russian doll caching patterns. |
| license | MIT |
| metadata | {"version":"1.1.0","hermes":{"tags":["Rails","Caching","Performance","Patterns"],"related_skills":["rails-testing-patterns","activerecord-application-query-optimization"]}} |
Use touch cascades so parent records auto-invalidate when children update:
class Image < ApplicationRecord
belongs_to :viewable, polymorphic: true, touch: true
end
Costs to weigh: every child save issues an extra parent UPDATE — on hot parents (many
concurrent child writes) that's row-lock contention and write amplification; bulk child
updates become touch storms. And the cascade is one level: Russian-doll invalidation up a
deeper graph needs touch: true at EVERY intermediate belongs_to, paired with nested
cache blocks in the views keyed on each record.
Clear all layers: Rails.cache.delete(key) (app cache), @cached_value = nil (memoization), reload (association cache).
Routing caches storing record IDs cause sporadic 404s when cached IDs no longer exist. Use atomic fetch with stampede prevention:
record = Rails.cache.fetch(cache_key,
expires_in: 10.seconds,
race_condition_ttl: 5.seconds) do
find_by(name: lookup_name)
end
Simpler alternative: for indexed lookups (<1ms), shrink TTL from minutes to 10 seconds — zero logic changes; the stale window shrinks proportionally to the TTL cut (e.g. 1-5min → 10s).
For tenant/subdomain resolution specifically, a stale cached ID is not just a 404: if the name is freed and reassigned within the TTL window, requests can resolve to the WRONG tenant's record — cross-tenant exposure. That is the concrete reason the security note below says to consider no cache at all on those paths.
| TTL | Use Case | Recommendation |
|---|---|---|
| 10s | Routing/resolution (subdomain, tenant) | Default for routing |
| 30s | Stable data, higher traffic | Good middle ground |
| 1min | Very stable data | Maximum for routing |
| 5min+ | Static reference data | Avoid for routing |
For security-critical paths (multi-tenant resolution, auth): consider removing cache entirely. ~2ms per-request cost is negligible vs. data breach risk.
Check if already set before calling the setter — without early return, each partial/helper call re-evaluates:
def current_campaign
return Current.campaign if Current.campaign.present?
set_current_campaign
end
Nil never latches with this guard: when there legitimately IS no campaign, the setter
re-runs on every call. If absent-is-common, memoize the LOOKED-UP state (a
Current.campaign_resolved flag) rather than the value's presence.
Enable lograge, optionally suppressing ActionView render notifications (the unsubscribe lines, not lograge itself, are what removes render lines — a large reduction in render-heavy apps):
config.lograge.enabled = true
config.lograge.ignore_actions = ['HealthController#index']
ActiveSupport::Notifications.unsubscribe("render_template.action_view")
ActiveSupport::Notifications.unsubscribe("render_partial.action_view")
unsubscribe is global: it removes EVERY subscriber of that event — including APM
instrumentation (New Relic, Skylight, AppSignal, Datadog view-render metrics). If you run
an APM, skip the unsubscribe lines or your view breakdowns go silently blank.