Skip to content

Programmatic cache invalidation online #3969

Closed

Description

@fabianwohlfart

Describe the feature

Motivation
I want to let my editor choose when to invalidate the cache after content updates.

Problem
The current implementation sets maxAge, so the file may get's cached by the browser itself.
I have therefor no tool to revoke the browser cache or tell the browser to invalidate the cache.

Caveat
Please correct me if I am wrong or point me to the right direction if I missed something.

Solution
https://github.com/nitrojs/nitro/blob/main/src/runtime/internal/cache.ts#L283

If we would allow custom cacheControl we could customize the behavior as we want.
it could also be a function to be more flexible.

const cacheControl = [];
if (opts.customCacheControl) {
cacheControl.push(opts.customCacheControl)
} else if (opts.swr) {

}

Benefit
I could set customCacheControl to no-store and have always served the cached files until I regenerate them by a webhook call.

Additional information

  • Would you be willing to help implement this feature?

Activity

  1. added
    pending triage
    on Jan 23, 2026
  2. pi0 commented on Mar 19, 2026

    @pi0
    Member

    Programmatic cache invalidation is now available in ocache (used by Nitro v3) via invalidateCache() and .invalidate():

    // On the cached function directly
    await cachedFn.invalidate(...args);
    
    // Or standalone
    import { invalidateCache } from "ocache";
    await invalidateCache({
      options: { name: "myHandler", getKey: (id) => id },
      args: ["some-id"],
    });

    See unjs/ocache#8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions