ObjectStackObjectStack

Http Cache schema — API Protocol reference

HTTP Metadata Cache Protocol — Implements efficient HTTP-level metadata caching with ETag support.

HTTP Metadata Cache Protocol

Implements efficient HTTP-level metadata caching with ETag support. Implements P0 requirement for ObjectStack kernel.

Caching in ObjectStack

HTTP Cache (api/http-cache.zod.ts) - This File

  • Purpose: Cache API responses at HTTP protocol level
  • Technologies: HTTP headers (ETag, Last-Modified, Cache-Control), CDN
  • Configuration: Cache-Control headers, validation tokens
  • Use case: Reduce API response time for repeated metadata requests
  • Scope: HTTP layer, client-server communication

Application Cache (system/cache.zod.ts)

  • Purpose: Cache computed data, query results, aggregations
  • Technologies: Redis, Memcached, in-memory LRU
  • Configuration: TTL, eviction policies, cache warming
  • Use case: Cache expensive database queries, computed values
  • Scope: Application layer, server-side data storage

Features

  • ETag-based conditional requests (HTTP 304 Not Modified)
  • Cache-Control directives
  • Metadata versioning
  • Selective cache invalidation

Industry alignment: HTTP Caching (RFC 7234), Salesforce Metadata API

See also: ../../system/cache.zod.ts for application-level caching

Source: packages/spec/src/api/http-cache.zod.ts

TypeScript Usage

import { CacheControlSchema, CacheDirective, CacheInvalidationRequestSchema, CacheInvalidationResponseSchema, CacheInvalidationTarget, ETagSchema, MetadataCacheRequestSchema, MetadataCacheResponseSchema } from '@objectstack/spec/api';
import type { CacheControl, CacheDirective, CacheInvalidationRequest, CacheInvalidationResponse, CacheInvalidationTarget, ETag, MetadataCacheRequest, MetadataCacheResponse } from '@objectstack/spec/api';

// Validate data
const result = CacheControlSchema.parse(data);

CacheControl

Properties

PropertyTypeRequiredDescription
directivesEnum<'public' | 'private' | 'no-cache' | 'no-store' | 'must-revalidate' | 'max-age'>[]✅Cache control directives
maxAgenumberoptionalMaximum cache age in seconds (unit per HTTP Cache-Control max-age (RFC 9111 §5.2.2.1))
staleWhileRevalidatenumberoptionalAllow serving stale content while revalidating (seconds) (unit per HTTP Cache-Control stale-while-revalidate (RFC 5861 §3))
staleIfErrornumberoptionalAllow serving stale content on error (seconds) (unit per HTTP Cache-Control stale-if-error (RFC 5861 §4))

CacheDirective

Allowed Values

  • public
  • private
  • no-cache
  • no-store
  • must-revalidate
  • max-age

CacheInvalidationRequest

Properties

PropertyTypeRequiredDescription
targetEnum<'all' | 'object' | 'field' | 'permission' | 'layout' | 'custom'>✅What to invalidate
identifiersstring[]optionalSpecific resources to invalidate (e.g., object names)
cascadebooleanoptional (default: false)If true, invalidate dependent resources
patternstringoptionalPattern for custom invalidation (supports wildcards)

CacheInvalidationResponse

Properties

PropertyTypeRequiredDescription
successboolean✅Whether invalidation succeeded
invalidatednumber✅Number of cache entries invalidated
targetsstring[]optionalList of invalidated resources

CacheInvalidationTarget

Allowed Values

  • all
  • object
  • field
  • permission
  • layout
  • custom

ETag

Properties

PropertyTypeRequiredDescription
valuestring✅ETag value (hash or version identifier)
weakbooleanoptional (default: false)Whether this is a weak ETag

MetadataCacheRequest

Properties

PropertyTypeRequiredDescription
ifNoneMatchstringoptionalETag value for conditional request (If-None-Match header)
ifModifiedSincestringoptionalTimestamp for conditional request (If-Modified-Since header)
cacheControl{ directives: Enum<'public' | 'private' | 'no-cache' | 'no-store' | 'must-revalidate' | 'max-age'>[]; maxAge?: number; staleWhileRevalidate?: number; staleIfError?: number }optionalClient cache control preferences

Nested Shape: MetadataCacheRequest.cacheControl

PropertyTypeRequiredDescription
directivesEnum<'public' | 'private' | 'no-cache' | 'no-store' | 'must-revalidate' | 'max-age'>[]✅Cache control directives
maxAgenumberoptionalMaximum cache age in seconds (unit per HTTP Cache-Control max-age (RFC 9111 §5.2.2.1))
staleWhileRevalidatenumberoptionalAllow serving stale content while revalidating (seconds) (unit per HTTP Cache-Control stale-while-revalidate (RFC 5861 §3))
staleIfErrornumberoptionalAllow serving stale content on error (seconds) (unit per HTTP Cache-Control stale-if-error (RFC 5861 §4))

MetadataCacheResponse

Properties

PropertyTypeRequiredDescription
dataanyoptionalMetadata payload (omitted for 304 Not Modified)
etag{ value: string; weak?: boolean }optionalETag for this resource version
lastModifiedstringoptionalLast modification timestamp
cacheControl{ directives: Enum<'public' | 'private' | 'no-cache' | 'no-store' | 'must-revalidate' | 'max-age'>[]; maxAge?: number; staleWhileRevalidate?: number; staleIfError?: number }optionalCache control directives
notModifiedbooleanoptional (default: false)True if resource has not been modified (304 response)
versionstringoptionalMetadata version identifier

Nested Shape: MetadataCacheResponse.etag

PropertyTypeRequiredDescription
valuestring✅ETag value (hash or version identifier)
weakbooleanoptional (default: false)Whether this is a weak ETag

Nested Shape: MetadataCacheResponse.cacheControl

PropertyTypeRequiredDescription
directivesEnum<'public' | 'private' | 'no-cache' | 'no-store' | 'must-revalidate' | 'max-age'>[]✅Cache control directives
maxAgenumberoptionalMaximum cache age in seconds (unit per HTTP Cache-Control max-age (RFC 9111 §5.2.2.1))
staleWhileRevalidatenumberoptionalAllow serving stale content while revalidating (seconds) (unit per HTTP Cache-Control stale-while-revalidate (RFC 5861 §3))
staleIfErrornumberoptionalAllow serving stale content on error (seconds) (unit per HTTP Cache-Control stale-if-error (RFC 5861 §4))

On this page