Code Explainers

Code explainers tagged #ttl

typescript
import { Inject, Injectable, Logger } from '@nestjs/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Cache } from 'cache-manager';
import { InjectRepository } from '@nestjs/typeorm';

A cache-aside country lookup in NestJS

cache-aside dependency-injection batch-lookup
Intermediate 8 steps
typescript
type CacheEntry<V> = {
  value: V;
  computedAt: number;
};

A TTL cache keyed by object identity

caching weakmap generics
Intermediate 8 steps
php
<?php
 
namespace App\Http\Middleware;
 

Caching HTTP responses with Laravel middleware

middleware caching http
Intermediate 8 steps
go
package cache
 
import (
	"sync"

A thread-safe TTL cache in Go

concurrency mutex caching
Intermediate 9 steps
rust
use axum::{
    extract::State,
    http::StatusCode,
    Json,

Idempotent webhook handling in Axum

deduplication idempotency shared-state
Intermediate 8 steps
go
package middleware
 
import (
	"bytes"

Building a response cache middleware in Gin

middleware caching concurrency
Intermediate 8 steps
typescript
type AsyncFn<A extends unknown[], R> = (...args: A) => Promise<R>;
 
interface MemoizeOptions<A extends unknown[]> {
  keyFn?: (...args: A) => string;

Memoizing async functions with TTL in TypeScript

memoization generics promises
Advanced 8 steps
php
<?php
 
namespace App\Security;
 

A fixed-window rate limiter on APCu

rate-limiting fixed-window caching
Intermediate 8 steps