caching

kotlin
package com.example.myapp.utils

import android.content.Context
import android.graphics.drawable.Drawable
import android.widget.ImageView
import com.bumptech.glide.Glide

Glide for image loading and caching

kotlin android glide
by Alex Chen 2 tabs
java
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Time-Based Caffeine Cache for Expensive Currency Rate Lookups in Spring

caffeine caching spring
by codesnips 3 tabs
ruby
module Cacheable
  extend ActiveSupport::Concern

  def cache_query(prefix, scope, expires_in: 15.minutes)
    key = [prefix, cache_version_token(scope)].join("/")

Targeted Query Caching for Expensive Endpoints

rails activerecord performance
by codesnips 3 tabs
sql
-- Create materialized view
CREATE MATERIALIZED VIEW user_statistics AS
SELECT
  users.id,
  users.username,
  COUNT(DISTINCT orders.id) AS order_count,

Materialized views for performance optimization

postgresql materialized-views performance
by Maria Garcia 2 tabs
python
CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379/1',
        'OPTIONS': {
            'CLIENT_CLASS': 'django_redis.client.DefaultClient',

Django redis caching strategies

django python redis
by Priya Sharma 2 tabs
erb
<%# Fragment caching - caches rendered HTML %>
<% cache @product do %>
  <h1><%= @product.name %></h1>
  <p><%= @product.description %></p>
  <p>Price: $<%= @product.price %></p>
<% end %>

Rails caching strategies for performance

ruby rails caching
by Sarah Mitchell 4 tabs
typescript
import { SetMetadata } from '@nestjs/common';

export const CACHEABLE_KEY = 'cacheable:options';

export type VaryDimension = 'user' | 'tenant' | 'query';

Per-Route Response Caching in NestJS with a Custom CacheInterceptor and Cache Key Builder

nestjs caching interceptors
by codesnips 4 tabs
typescript
import { Injectable } from '@nestjs/common';

type Completed = { status: 'completed'; statusCode: number; body: unknown; expiresAt: number };
type InFlight = { status: 'in-flight'; startedAt: number };
type Record = Completed | InFlight;

Idempotency-Key Interceptor in NestJS to Debounce Duplicate Form Submissions

nestjs idempotency interceptor
by codesnips 4 tabs
typescript
import type { Redis } from "ioredis";

export interface RawEntry {
  member: string;
  score: number;
}

Redis-Backed Paginated Leaderboard With a Repository and Ranking Service

redis leaderboard pagination
by codesnips 3 tabs
ruby
class Current < ActiveSupport::CurrentAttributes
  attribute :user, :request_id

  def permissions
    @permissions ||= PermissionSet.new(user)
  end

Memoizing Computed User Permissions Per Request with Current Attributes in Rails

rails authorization caching
by codesnips 4 tabs
ruby
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

Cache Stampede Protection with race_condition_ttl

rails caching performance
by codesnips 3 tabs
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