Coder Social home page Coder Social logo

wetr3 / nuxt-elastic-cache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vladstepanov/nuxt-elastic-cache

0.0 0.0 0.0 115 KB

Flexible fully transparent cache middleware for Nuxt3 SSR rendering with Redis support

Home Page: https://www.npmjs.com/package/nuxt-elastic-cache

License: MIT License

TypeScript 97.84% Vue 2.16%

nuxt-elastic-cache's Introduction

nuxt-elastic-cache

npm version npm downloads License Nuxt

Flexible fully transparent cache middleware for Nuxt3 SSR rendering with Redis support

Quick Setup

  1. Add nuxt-elastic-cache dependency to your project
# Using pnpm
pnpm add -D nuxt-elastic-cache

# Using yarn
yarn add --dev nuxt-elastic-cache

# Using npm
npm install --save-dev nuxt-elastic-cache
  1. Add nuxt-elastic-cache to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'nuxt-elastic-cache'
  ],
  elasticCache: {
    enabled: true,
    storage: {
      type: 'redis',
      redis: {
        url: 'redis://localhost:6379',
        /* Or */
        host: 'localhost',
        port: 6379,
        username: '..',
        password: '..',
        db: 0
      },
    },
    pages: [
      /*
       * Powered by https://github.com/isaacs/minimatch
       * Also supports RegExp
      */
      '/about/*',
      '/about/**/*ending'
    ],
    key (req) {
      return `c-${yourCustomLogic(req)}`
    }
  },
})

Configuration

Top level configuration

Option Type required Description Default
enabled boolean No To enable/disable the SSR cache true
storage Storage No Config storage for cache undefined
pages string|RegExp| Array<string| RegExp> No Pages to be cached []
key (req: IncomingMessage) => string | false No Can be used to generate custom key. Return falsy value to bypass cache (req) => req.url

Storage configuration

Option Type Required Description Default
type 'memory' | 'redis' Yes Cache storage 'memory'
memory.ttl number No Number in seconds to store page in cache 1 hour
memory.max number No Max number of pages to store in cache. If limit is reached, least recently used page is removed 500
redis.url string No String to Redis instance. This option has priority over options below. undefined
redis.ttl number No Number in seconds to store page in cache 1 hour
redis.host string No Redis instance host undefined
redis.port number No Redis instance port undefined
redis.username string No Redis instance username undefined
redis.password string No Redis instance password undefined
redis.db number No Redis instance db undefined

That's it! You can now use nuxt-elastic-cache in your Nuxt app โœจ

Development

# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the playground
npm run dev:build

# Run ESLint
npm run lint

# Run Vitest
npm run test
npm run test:watch

# Release new version
npm run release

Caveat

important security warning: don't load secret keys such as user credential on the server for cached pages. this is because they will cache for all users!

nuxt-elastic-cache's People

Contributors

vladstepanov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.