Code Explainers

Code explainers tagged #caching

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