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

fix: no cache dir created when enableCaching is set to false #191

Closed
wants to merge 1 commit into from

Conversation

its-jz
Copy link

@its-jz its-jz commented Nov 20, 2024

why

A tmp/.cache directory is created even when enableCaching is set to false.

what changed

  1. Passing enableCaching all the way down to BaseCache
  2. If enableCaching is false, ensureCacheDirectory will not create a directory
  3. Added a devdependency because it eems like "@playwright/test" was missing

test plan

@@ -16,6 +16,7 @@ export class BaseCache<T extends CacheEntry> {
private readonly CACHE_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000; // 1 week in milliseconds
private readonly CLEANUP_PROBABILITY = 0.01; // 1% chance

protected enableCaching: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make sense to add this field here. Rather, we should just not init a cache if enableCaching is set to false in LLMProvider and actHandler. It makes more sense to make the cache default undefined in LLMProvider and actHandler, and before a cache operation there, check enableCaching.

@@ -71,7 +74,7 @@ export class BaseCache<T extends CacheEntry> {
}

protected ensureCacheDirectory(): void {
if (!fs.existsSync(this.cacheDir)) {
if (this.enableCaching && !fs.existsSync(this.cacheDir)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an antipattern. Since this method is protected, it can only be called from other cache objects. If we just don't init a cache, the directory won't be created

@@ -273,9 +273,8 @@ export class StagehandActHandler {

this.logger({
category: "action",
message: `Clicked element, ${
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you format with prettier to keep the diff relevant to code changes

@@ -27,6 +27,7 @@
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.9",
"@playwright/test": "^1.49.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added?

@kamath
Copy link
Contributor

kamath commented Nov 21, 2024

Addressing in #197

@kamath kamath closed this Nov 21, 2024
@kamath
Copy link
Contributor

kamath commented Nov 21, 2024

Sincerely appreciate your help and time here in trying to resolve this issue! There might be a simpler short-term fix in #197 in the meantime

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

Successfully merging this pull request may close these issues.

2 participants