Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically purge cache on version change #416

Open
NathanFlurry opened this issue Jun 26, 2024 — with Linear · 2 comments
Open

Automatically purge cache on version change #416

NathanFlurry opened this issue Jun 26, 2024 — with Linear · 2 comments
Assignees

Comments

Copy link
Member

NathanFlurry commented Jun 26, 2024

Motivation

OpenGB doesn't manage cache compat between versions. It should auto-purge the cache if the version changes.

@NathanFlurry NathanFlurry self-assigned this Jun 26, 2024
Copy link

linear bot commented Jun 26, 2024

Copy link

greptile-apps bot commented Jun 26, 2024

To automatically purge the cache on version change, update the loadCache function in src/build_state/cache.ts to reset the cache if the version has changed. Here are the specific steps:

  1. Modify the loadCache function to include a version check and reset the cache if the version has changed:
export async function loadCache(project: Project): Promise<Cache> {
  const buildCachePath = genPath(project, CACHE_PATH);

  // Read hashes from file
  let persist: CachePersist;
  if (await exists(buildCachePath)) {
    try {
      const oldCacheAny: any = JSON.parse(
        await Deno.readTextFile(buildCachePath),
      );

      // Validate version
      if (oldCacheAny.version == CACHE_VERSION) {
        persist = oldCacheAny;
      } else {
        persist = createEmptyCachePersist();
        await writeCache(project, { persist, hashDiffs: new Map() }); // Purge cache
      }
    } catch {
      // If parsing fails or the cache isn't readable, reset the cache.
      persist = createEmptyCachePersist();
    }
  } else {
    persist = createEmptyCachePersist();
  }

  return {
    persist,
    hashDiffs: new Map(),
  };
}

This ensures that the cache is automatically purged and reset whenever the CACHE_VERSION changes.

References

/src/build_state/cache.ts

Ask Greptile · Edit Issue Bot Settings

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

No branches or pull requests

1 participant