http-caching

ruby
module Api
  module V1
    class UsersController < BaseController
      def show
        user = User.includes(:profile).find(params[:id])

ETags for conditional requests and caching

rails caching http-caching
by Alex Kumar 1 tab
ruby
module ConditionalGet
  extend ActiveSupport::Concern

  private

  def render_conditional(resource, extra: nil)

ETag + Conditional GET for JSON API

rails performance http-caching
by codesnips 2 tabs
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
java
package com.example.caching.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.ShallowEtagHeaderFilter;

Conditional GET with ETag ShallowEtagHeaderFilter and Cache-Control in Spring Boot

spring-boot http-caching etag
by codesnips 3 tabs
typescript
import { createHash } from "crypto";
import { Request, Response } from "express";

export function computeEtag(body: string): string {
  const digest = createHash("sha1").update(body).digest("base64");
  return `"${digest}"`;

ETag + conditional GET for read-heavy endpoints

performance express http-caching
by codesnips 3 tabs
python
import hashlib
from functools import wraps

from flask import request, make_response
from redis import Redis

Flask ETag Caching for an Expensive Endpoint with Conditional 304 Handling

flask http-caching etag
by codesnips 2 tabs
ruby
module Paginatable
  extend ActiveSupport::Concern

  Page = Struct.new(:records, :next_cursor, keyword_init: true)

  DEFAULT_LIMIT = 25

Cursor-Paginated Rails API with ETag and Conditional GET Caching

rails api http-caching
by codesnips 3 tabs
javascript
const crypto = require('crypto');

function computeStrongEtag(body) {
  const buf = Buffer.isBuffer(body) ? body : Buffer.from(String(body));
  const digest = crypto.createHash('sha1').update(buf).digest('base64');
  return '"' + digest + '"';

ETag-Based HTTP Caching in Express With 304 Not Modified Handling

express http-caching etag
by codesnips 3 tabs
ruby
require 'digest'
require 'json'

module CacheHelpers
  def cache_control_public(max_age = 60)
    cache_control :public, :must_revalidate, max_age: max_age

Conditional GET in Sinatra with ETag and Last-Modified for Cacheable JSON Endpoints

sinatra http-caching etag
by codesnips 3 tabs