Skip to content

Commit c9d38e2

Browse files
committed
Add docs on caching
1 parent 661d946 commit c9d38e2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Here is an example of UI you can build with this adapater: [songs-search.typesen
2121
- [With vue-instantsearch](#with-vue-instantsearch)
2222
- [With angular-instantsearch](#with-angular-instantsearch)
2323
- [Widget Specific Instructions](#widget-specific-instructions)
24+
- [Caching](#caching)
2425
- [Compatibility](#compatibility)
2526
- [Development](#development)
2627
- [Help](#help)
@@ -636,6 +637,46 @@ search = instantsearch({
636637
});
637638
```
638639

640+
## Caching
641+
642+
There are two modes of caching:
643+
644+
1. **Server-side caching:**
645+
646+
To enable server-side caching, add a parameter called `useServerSideSearchCache: true` in the `server` configuration block of the typesense-instantsearch-adapter like this:
647+
648+
```javascript
649+
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
650+
server: {
651+
apiKey: "...",
652+
nearestNode: {...},
653+
nodes: [...],
654+
useServerSideSearchCache: true // <<< Add this to send use_cache as a query parameter instead of post body parameter
655+
},
656+
additionalSearchParameters: {...}
657+
});
658+
```
659+
660+
This will cause the adapter to add `?use_cache=true` as a URL query parameter to all search requests initiated by the adapter, which will then cause Typesense Server to enable server-side caching for these requests.
661+
662+
2. **Client-side caching:**
663+
664+
The adapter also has client-side caching enabled by default, to prevent unnecessary network calls to the server. The TTL for this client-side cache can be configured like this:
665+
666+
```javascript
667+
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
668+
server: {
669+
apiKey: "...",
670+
nearestNode: {...},
671+
nodes: [...],
672+
cacheSearchResultsForSeconds: 2 * 60 // <<< Add this to configure the TTL for client-side cache in the browser
673+
},
674+
additionalSearchParameters: {...}
675+
});
676+
```
677+
678+
679+
639680
## Compatibility
640681

641682
| Typesense Server | typesense-instantsearch-adapter | instantsearch.js | react-instantsearch | vue-instantsearch | angular-instantsearch |

0 commit comments

Comments
 (0)