json.array! @posts do |post|
json.cache! ['v1', post], expires_in: 1.hour do
json.id post.id
json.title post.title
json.excerpt post.excerpt
json.published_at post.published_at
import { randomBytes, createHash } from "crypto";
import jwt from "jsonwebtoken";
import { RefreshTokenStore } from "./store";
const ACCESS_SECRET = process.env.ACCESS_SECRET!;
const ACCESS_TTL = "15m";
type AsyncTask = () => Promise<void>;
export interface GuardOptions {
name: string;
logger?: Pick<Console, "info" | "warn" | "error">;
}
require "timeout"
module HealthCheck
class Probe
Result = Struct.new(:name, :status, :latency_ms, :critical, :error, keyword_init: true) do
def healthy?
class FeatureFlag < ApplicationRecord
validates :key, presence: true, uniqueness: true
validates :percentage, inclusion: { in: 0..100 }
after_commit :expire_cache
class ShardedCounter
SHARDS = 16
SNAPSHOT_TTL = 10 # seconds
def initialize(name, redis: REDIS)
@name = name
class Rack::Attack
Rack::Attack.cache.store = ActiveSupport::Cache::RedisCacheStore.new(url: ENV['REDIS_URL'])
safelist('allow-localhost') do |req|
req.ip == '127.0.0.1' || req.ip == '::1'
end
package cache
import (
"context"
"github.com/redis/go-redis/v9"
class Post < ApplicationRecord
# View counter - increments without hitting the database
kredis_counter :view_count, expires_in: 1.day
# Recent viewers list - stores last 10 viewer IDs
kredis_unique_list :recent_viewers, limit: 10
module Idempotency
extend ActiveSupport::Concern
included do
before_action :check_idempotency_key, only: [:create, :update]
after_action :store_idempotent_response, only: [:create, :update]
:concurrency: 10
:queues:
- [critical, 4]
- [default, 2]
- [low, 1]
bind 127.0.0.1 10.0.0.15
protected-mode yes
port 6379
rename-command FLUSHALL ""
rename-command CONFIG ""
aclfile /etc/redis/users.acl