class LeaderboardCache
TOP_KEY = "leaderboard:top".freeze
STATS_KEY = "leaderboard:stats".freeze
def top_players
Rails.cache.fetch(TOP_KEY, expires_in: 5.minutes, race_condition_ttl: 15.seconds) do
from django.core.cache import cache
class RateLimiter:
def __init__(self, scope, limit, window_seconds):
self.scope = scope
class TrendingPostsService
CACHE_KEY = 'trending_posts:v1'.freeze
CACHE_TTL = 15.minutes
def self.call(limit: 10)
Rails.cache.fetch(CACHE_KEY, expires_in: CACHE_TTL) do
const { z } = require('zod');
const ConfigSchema = z.object({
env: z.enum(['development', 'test', 'production']).default('development'),
port: z.coerce.number().int().positive().default(3000),
database: z.object({
'use strict';
function dedupeAsync(producer, keyFn) {
const pending = new Map();
const resolveKey = keyFn || ((...args) => JSON.stringify(args));
class ApplicationController < ActionController::Base
before_action :set_turbo_cache_control
class_attribute :turbo_no_cache, default: false
def self.no_turbo_cache
package com.example.demo.config;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;
class LastSeenTracker
THROTTLE = 5.minutes
PENDING_KEY = "pending:last_seen".freeze
class << self
def touch(user_id, at: Time.current)
class DashboardMetrics
include ActiveModel::Model
attr_reader :account
def initialize(account)
<?php
namespace App\Report;
use App\Repository\OrderRepository;
use Symfony\Contracts\Cache\ItemInterface;
module RequestStore
def self.store
Thread.current[:request_store] ||= {}
end
def self.fetch(key)
package api
import "net/http"
func ETag(w http.ResponseWriter, r *http.Request, etag string) bool {
w.Header().Set("ETag", etag)