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

Manually setting cache #194

Open
betweenbrain opened this issue Apr 17, 2023 · 7 comments
Open

Manually setting cache #194

betweenbrain opened this issue Apr 17, 2023 · 7 comments
Labels
✨ enhancement New feature or request

Comments

@betweenbrain
Copy link

Hello,

We are looking to achieve something very similar to issue #29. In reviewing https://villus.logaretm.com/plugins/cache/#clearing-cache, it seems like one should be able to call cachePlugin.setCacheResult(...), but my initial attempts following the example throws TypeError: j.setCacheResult is not a function. Is this expected?

@logaretm
Copy link
Owner

logaretm commented May 9, 2023

Sorry for the delay, just got around to this. The plugin doesn't exposesetCacheResult, only the clear method.

But I guess we could expose it, will try to tackle it this week. PR is welcome as well, thanks for reporting this.

@logaretm logaretm added the ✨ enhancement New feature or request label May 9, 2023
@betweenbrain
Copy link
Author

Thanks for the response! And, now I owe you an apology for the delay 😆

Would exposing it be as simple as adding something like cachPlugin.setCacheResult = setCacheResult(operation, result); to https://github.com/logaretm/villus/blob/main/packages/villus/src/cache.ts#L80?

@logaretm
Copy link
Owner

Hello, it is the other way around. Sorry, I didn't find the time to work on it, busy with vee-validate at the moment.

It is as simple as you suggested. But how would you set the cache yourself? Would you pass an object containing the query and variables? Because it relies on key being provided, so it might be worth regenerating the key before then.

cachPlugin.setCacheResult = function (operation, result) {
  // getQueryKey imported from utils
  const key = operation.key || getQueryKey(operation);
 setCacheResult({ key, ...operation }, result);
}

@betweenbrain
Copy link
Author

Hello, thanks again for the response. No apologies are needed!

But how would you set the cache yourself? Would you pass an object containing the query and variables?

Yes, that's exactly how I was thinking we would do it.

Is there anything that I can do to help move this forward?

@logaretm
Copy link
Owner

Is there anything that I can do to help move this forward?

Feel free to PR it if you have the time, I know it's a 1 liner but I usually do open-source on weekends and whenever I can sneak in work days. I will take it on by the weekend if you won't have the time.

@betweenbrain
Copy link
Author

Great! PR submitted at #198. I hope that helps.

@betweenbrain
Copy link
Author

@logaretm do you have a chance to review the above PR? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants