Skip to content

Oren-Exon/next-15-cache-handler

Repository files navigation

self-hosted next-15 with redis cache (no CDN for pages)

This project demos latest next application with redis caching-layer.

More info:

Requirements

  • nodejs v18 or higher
  • docker (only required for npm start command)

Available scripts

  • npm run dev - Start development server with mock API
  • npm run build - Build the application for production
  • npm run start - Build and Start production server using Docker Compose
  • npm run lint - Run ESLint to check code quality
  • npm run typecheck - Run TypeScript type checking
  • npm run api-mocks - Start mock API server

Available Routes

Pages

  • / - Home page with Next.js welcome content
  • /count/[keyword] - Dynamic route that fetches count data for a given keyword (revalidates every 500 seconds)
  • /lpvs/[lpv]/verticals/best/search/[keyword] - Nested dynamic route for search functionality (revalidates every 120 seconds)
    • Note: Only works when lpv parameter equals "10000"

API Routes

  • POST /api/revalidate/path?path=<path> - Revalidates a specific path in the cache (currently not working)
  • POST /api/revalidate/tag?tag=<tag> - Revalidates pages and api-requests caches
    • for example POST /api/revalidate/tag?tag=10000:best:search:tv - revalidates lpv 10000 best vertical search/tv page

Rewrite Routes

This application uses two types of URL rewrites to provide clean, SEO-friendly URLs while maintaining the underlying route structure:

Next.js Config Rewrites

Configured in next.config.ts:

  • /foo/:path*/lpvs/10000/verticals/best/search/:path*
    • Example: /foo/tv/lpvs/10000/verticals/best/search/tv
    • This rewrite works well with caching (uses the internal route cache)

Middleware Rewrites

Configured in middleware.ts:

  • /search/:path*/lpvs/10000/verticals/best/search/:path*
    • Example: /search/tv/lpvs/10000/verticals/best/search/tv
    • This rewrite works well with caching (uses the internal route cache)

Testing Rewrites

You can test the rewrite functionality by visiting:

  • http://localhost:3000/search/tv (middleware rewrite) - cache works
  • http://localhost:3000/foo/tv (config rewrite) - cache works

Issues

Revalidate path does not work

About

use custom cache handler for next-v15

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published