typesense / typesense-js

JavaScript / TypeScript client for Typesense
https://typesense.org/docs/api
Apache License 2.0
400 stars 74 forks source link

adds cache clearing functionality #132

Closed uncvrd closed 2 years ago

uncvrd commented 2 years ago

Change Summary

This PR exposes a new method, clearCache on SearchClient which allows for a user to programmatically clear the Typesense client cache. Which is useful for having instant access to new documents after mutations.

To do this, I had to create a method to reset the cache in RequestWithCache and then "bubble up" this method through Multisearch and SearchOnlyDocuments to finally expose it in the SearchClient class. Alternatively it might be nice to instantiate the cache at the SearchClient level to pass it down, but I didn't want to mess with current implementations.

To clear cache, multisearch is straight forward but with individual collections, we must loop through all collections to reset.

I also added two tests to SearchClient, which confirm that the cache is being reset properly, but I'm not sure this is the best location or implementation for them.

Hope this helps or gets us in the right direction!

PR Checklist

jasonbosco commented 2 years ago

Thank you @uncvrd!

uncvrd commented 2 years ago

of course - happy to help!

jasonbosco commented 2 years ago

I've published this in v1.4.1-0. Could you give it a shot?

uncvrd commented 2 years ago

@jasonbosco Def! I can confirm that this works for my use case!