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
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)
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)
package pricecache
import (
"context"
"sync"
class BatchLoader {
constructor(batchFn, { cacheKeyFn = (k) => k } = {}) {
this.batchFn = batchFn;
this.cacheKeyFn = cacheKeyFn;
this.cache = new Map();
this.queue = [];
class Product < ApplicationRecord
has_many :reviews, dependent: :destroy
scope :published, -> { where(published: true) }
def average_rating
package web
import (
"embed"
"io/fs"
)