Code Explainers
Code explainers tagged #caching
ruby
class ReportGenerator def initialize(account, period) @account = account @period = period
Memoized report metrics in Ruby in Rails
memoization
query-composition
service-object
Intermediate
7 steps
php
<?php namespace App\Services;
Caching tenant dashboard metrics in Laravel
caching
multi-tenancy
aggregation
Intermediate
7 steps
java
@Service public class ProductCatalogService { private final ProductRepository productRepository;
How Spring cache annotations keep data fresh
caching
cache-invalidation
dependency-injection
Intermediate
7 steps
python
from django.core.cache import cache from rest_framework.throttling import SimpleRateThrottle
A login rate throttle in Django REST Framework
rate-limiting
caching
throttling
Intermediate
8 steps
php
function memoize(callable $fn): callable { $cache = [];
How memoization works in PHP closures
memoization
closures
higher-order-functions
Intermediate
8 steps
rust
use std::collections::HashMap; pub struct Memoizer<K, V, F> { cache: HashMap<K, V>,
A generic memoizer in Rust
memoization
generics
caching
Intermediate
6 steps
ruby
class SessionsController < ApplicationController MAX_ATTEMPTS = 5 THROTTLE_WINDOW = 15.minutes
Throttling failed logins in Rails
rate-limiting
authentication
caching
Intermediate
7 steps
java
import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.math.BigInteger;
A thread-safe memoized factorial cache
memoization
thread-safety
caching
Intermediate
6 steps
php
<?php namespace App\Security;
A fixed-window rate limiter on APCu
rate-limiting
fixed-window
caching
Intermediate
8 steps
python
from functools import wraps def memoize(func):
Building a memoize decorator in Python
decorators
closures
memoization
Intermediate
5 steps
typescript
import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, shareReplay } from 'rxjs';
Caching HTTP config in an Angular service
caching
observables
dependency-injection
Intermediate
6 steps
typescript
import { CACHE_MANAGER, CacheInterceptor, } from '@nestjs/cache-manager';
A tenant-aware HTTP cache in NestJS
caching
interceptors
multi-tenancy
Intermediate
7 steps
ruby
class ProductCatalog def featured_products Rails.cache.fetch("catalog/featured_products", expires_in: 12.hours) do Product.where(featured: true)
Caching patterns with Rails.cache.fetch
caching
cache-keys
expiry
Intermediate
5 steps
typescript
class LRUCache<K, V> { private readonly capacity: number; private readonly map: Map<K, V>;
Building an LRU cache on a JS Map
caching
data-structures
generics
Intermediate
8 steps