Course Overview
Locked video preview

Paid video

Please purchase the course to watch.

Preparing for production

Adding page caching

Here is a summary of the video transcript:

  • Introduction to Caching
    Caching is a technique for temporarily storing frequently accessed or expensive-to-compute data to improve performance. It reduces database and server load while improving response times and user experience.

  • In-Memory Cache vs. Redis
    An in-memory cache stores data in application memory and is cleared on restart or deployment. Unlike Redis, it does not persist across restarts but offers faster access due to RAM-based lookups and simpler setup.

  • Using the Otter Caching Library
    The implementation uses the Otter Go library, a high-performance, type-safe generic cache. A custom generic cache wrapper is created with configurable size and time-to-live (TTL) settings.

  • Cache Abstraction Design
    A generic cache struct is defined with helper methods: get, set, delete, and invalidateAll. This abstraction simplifies cache usage and enables easy invalidation when content changes.

  • Page-Level Caching
    Two caches are introduced: one for rendered page components and another for string-based assets. The home page and article pages are cached using unique keys based on parameters such as pagination and slugs.

  • Asset Caching (Robots and Sitemap)
    Static responses like robots.txt and sitemap.xml are cached to avoid repeated regeneration. Cached values are returned when available, otherwise generated and stored for future requests.

  • Performance and Extensibility Considerations
    Cache size and TTL values are configurable and should be tuned based on memory constraints. The solution is extensible and can be enhanced with advanced options or replaced with persistent caching if needed.

  • Next Steps: Browser Caching
    The next step introduces browser-level caching for static assets such as CSS and JavaScript, further reducing server requests and improving load times.