4

I'm using the algolia client directly in my node js backend so i don't use instantsearch.js.

I can easily querying/indexing/updating etc. my algolia index but i can't find a way to clear the cache because my app always need to display an updated hits list in real time.

i've tried

client.initIndex('my index');
client.clearCache()

But without success. Always need to force unmount/remount manually my app to see the updated hits list.

Any solution ?

John doe
  • 3,680
  • 7
  • 31
  • 65

1 Answers1

4

Its an old question but since there are no responses ....

Docs

Given the following instantiation:

const client = algoliasearch('H58KBL9VKQ', '••••••••••••••••••••');
const index = client.initIndex('your_index_name');

There are two methods.

client.clearCache() - when using multiple indices

index.clearCache() - when querying one index specifically

Note that BOTH return a Promise and both work only in the BROWSER, since the Node API doesn't cache results, there is no cache to clear.

Tremendus Apps
  • 1,497
  • 12
  • 20
  • Note the the clearCache() method is now async since V4: so you will have to change to client.clearCached().then(() => {...}); see https://www.algolia.com/doc/api-client/getting-started/upgrade-guides/javascript/#the-clearcache-method – Chris Herbst Jul 22 '20 at 12:46
  • I just verified with Algolia API support. You cannot clear cache on just one specific index like that. That is incorrect. – jiminssy Sep 02 '20 at 08:46
  • 2
    Actually you could when the answer was written 2 years ago. But the API has changed substantially over the past year. No need for a downvote @jiminssy – Tremendus Apps Sep 04 '20 at 12:55
  • Please consider editing and updating the answer to indicate that it no longer works. – jiminssy Sep 26 '20 at 21:28
  • Their support is wrong, or things have changed back, then. `client.clearCache()` definitely exists and works. https://github.com/algolia/algoliasearch-client-javascript/search?q=clearcache It is a promise so be mindful of that. – corysimmons May 18 '21 at 02:04