Novel
Get NovelGuidesAPI Reference
Latest - 2025.1.0
Latest - 2025.1.0
  • Welcome to Novel
  • Start
  • Philosophy
  • Tech Stack
  • Releases
  • Versions
  • Changelog
  • License
  • Privacy
  • Warranty
  • Security Policy
  • Errors
    • Cannot start Novel
    • Unauthorized
    • Invalid Session
    • Validation Failed
  • Novel Server
    • Getting Started
    • Project Structure
    • With Novel Web
    • Configuration
    • Novel CLI
      • novel dev
      • novel start
      • novel new
    • Novel API
      • API Reference
    • Database
      • Caching
    • Migrations
    • Models
    • Routing
      • Route Directives
      • Middleware
      • Request Helpers
      • Schema
    • Sessions
    • Authentication
      • Passwords
      • Magic Links
      • Two-Factor Authentication
      • Forget Password
      • Email Verification
      • OAuth2 Support
    • Authorization
    • Users
    • Organizations
    • Subscriptions
    • Pricing
    • Validation
    • Mail
    • Notifications
    • API Keys
    • Events
    • Errors
    • Feature Flags
    • Uploading Files
    • Testing
    • Scheduled Cron Jobs
    • Background Jobs
    • Sockets
    • Logging
    • Telemetry
    • Deployment
  • Novel Web
    • Getting Started
    • Configuration
    • Project Structure
    • Routing
    • Layout and Styles
    • Authentication
    • Authorization
    • Requests
    • Request Files
    • Validation
    • Components
      • Button
      • Alerts
      • Copybox
      • Inline Notify
      • Input
      • Select
      • Toast
      • Toggle
      • Upload
      • Stripe Card
    • Hooks
      • useSession
      • useMobile
      • getSession
      • useFeature
      • useAuthorized
      • useNotification
      • useSocket
    • Localstorage
    • Errors
    • Internationalization (i18n)
    • Constants
    • Feature Flags
    • Testing
    • Telemetry
    • Deployment
    • Devtools (Alpha)
Powered by GitBook
On this page
  • Usage
  • cache.get(key: string)
  • cache.set(key: string, value: any, ttl?: number)
  • cache.clear(key: string)
  • cache.touch(key: string, ttl: number)

Was this helpful?

  1. Novel Server
  2. Database

Caching

Novel's philosophy of low overhead affects the function of caching because it do not use traditional caching services.

Caching in Novel makes use of PostgreSQL's SKIP UNLOGGED feature. So the caching layer is within the database layer itself.

The cache is located in the cache table.

Usage

You can use the cache through

feature.ts
import cache from 'novel/cache';

await cache.set('key', value);

await cache.get('key');

The cache key is hashed and stored in the cache table.

cache.get(key: string)

You can get a cached value from the database through a simple function.

cache.set(key: string, value: any, ttl?: number)

You can set the value as well as a TTL for the key you want to set

cache.clear(key: string)

Remove a key from the cache.

cache.touch(key: string, ttl: number)

If you want to extend the TTL of a cached key.

Last updated 5 months ago

Was this helpful?