javascript
const CACHE_NAME = 'swr-api-v1';
const STAMP_HEADER = 'x-cached-at';

async function open() {
  return caches.open(CACHE_NAME);
}

Stale-While-Revalidate Fetch Wrapper Using the Browser Cache API

cache-api stale-while-revalidate fetch
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
python
import base64
import json

from django.core.exceptions import BadRequest

Cursor-Paginated JSON Feed with a Django Class-Based ListView

django pagination cursor-pagination
by codesnips 3 tabs
rust
use async_trait::async_trait;
use serde::Serialize;

#[derive(Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Status {

Aggregating Subsystem Health Checks Behind an Axum /healthz Endpoint

axum tokio health-check
by codesnips 3 tabs
java
package com.example.tracing;

import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;

Propagate a Correlation ID Through Servlet Requests With MDC and a Feign Interceptor

java servlet filter
by codesnips 3 tabs
javascript
const express = require('express');
const multer = require('multer');
const os = require('os');
const fs = require('fs/promises');
const { parseCsvStream } = require('./csvStreamParser');

Stream and Validate Large CSV Uploads Row-by-Row with Node Streams and Backpressure

nodejs streams csv
by codesnips 3 tabs
ruby
module Retryable
  module_function

  def with_retries(tries: 3, base: 0.3, cap: 5.0, on: [StandardError])
    attempt = 0
    begin

Retry a Flaky HTTP Call with Exponential Backoff Using a Rails Service Object

rails http retries
by codesnips 3 tabs
javascript
const jwt = require('jsonwebtoken');

const ACCESS_SECRET = process.env.JWT_ACCESS_SECRET;
const REFRESH_SECRET = process.env.JWT_REFRESH_SECRET;
const ISSUER = 'api.example.com';
const AUDIENCE = 'example-web';

Sign and Verify JWT Access Tokens in Express Auth Middleware

express jwt authentication
by codesnips 3 tabs
java
package com.example.storage;

import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;

Bind and Validate Grouped App Settings with @ConfigurationProperties in Spring Boot

spring-boot configuration validation
by codesnips 3 tabs
ruby
class CreateWebhookEvents < ActiveRecord::Migration[7.1]
  def change
    create_table :webhook_events do |t|
      t.string :event_id, null: false
      t.string :source, null: false, default: "stripe"
      t.string :event_type, null: false

Idempotent Stripe Webhook Processing with a Unique Event Key in Rails

rails postgres webhooks
by codesnips 4 tabs
rust
use std::collections::HashSet;
use std::hash::Hash;

pub struct DedupByKey<I, K, F> {
    inner: I,
    key_fn: F,

Order-Preserving Stream Deduplication by Key in Rust with a HashSet Guard

rust streams deduplication
by codesnips 3 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