caching

python
from django.core.cache import cache


class RateLimiter:
    def __init__(self, scope, limit, window_seconds):
        self.scope = scope

Rate-Limiting Django Password Reset Requests in a Form's clean() Method

django rate-limiting caching
by codesnips 3 tabs
ruby
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

Redis caching for expensive computations

rails redis caching
by Alex Kumar 1 tab
ruby
class ApplicationController < ActionController::Base
  before_action :set_turbo_cache_control

  class_attribute :turbo_no_cache, default: false

  def self.no_turbo_cache

Avoid caching sensitive pages in Turbo Drive

rails hotwire turbo
by codesnips 4 tabs
java
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;

Caching strategies with Spring Cache

java spring-boot caching
by David Kumar 2 tabs
ruby
class LastSeenTracker
  THROTTLE = 5.minutes
  PENDING_KEY = "pending:last_seen".freeze

  class << self
    def touch(user_id, at: Time.current)

Database “Last Seen” without Hot Row Updates

rails performance redis
by codesnips 3 tabs
ruby
class DashboardMetrics
  include ActiveModel::Model

  attr_reader :account

  def initialize(account)

Expiring Dashboard Fragment Caches with a Versioned Composite Cache Key in Rails

rails caching fragment-caching
by codesnips 3 tabs
ruby
module RequestStore
  def self.store
    Thread.current[:request_store] ||= {}
  end

  def self.fetch(key)

Hot Path Memoization (within request only)

rails performance memoization
by codesnips 4 tabs
go
package api

import "net/http"

func ETag(w http.ResponseWriter, r *http.Request, etag string) bool {
  w.Header().Set("ETag", etag)

ETag handling for conditional GETs (cheap caching)

go http caching
by Leah Thompson 1 tab
go
package pricecache

import (
	"context"
	"sync"

Collapse Concurrent Identical Requests in Go with singleflight

go singleflight concurrency
by codesnips 3 tabs
javascript
class BatchLoader {
  constructor(batchFn, { cacheKeyFn = (k) => k } = {}) {
    this.batchFn = batchFn;
    this.cacheKeyFn = cacheKeyFn;
    this.cache = new Map();
    this.queue = [];

Coalescing Concurrent Reads with a DataLoader-Style Batch Loader in Node

dataloader batching graphql
by codesnips 3 tabs
ruby
class Product < ApplicationRecord
  has_many :reviews, dependent: :destroy

  scope :published, -> { where(published: true) }

  def average_rating

Russian Doll Fragment Caching with Touch Propagation in Rails

rails caching fragment-caching
by codesnips 4 tabs
go
package web

import (
	"embed"
	"io/fs"
)

Serve Embedded Static Assets with embed.FS and Cache Headers in Go

go embed static-assets
by codesnips 3 tabs