Skip to content

Commit

Permalink
Add docs on caching
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbosco committed Nov 13, 2024
1 parent 661d946 commit c9d38e2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Here is an example of UI you can build with this adapater: [songs-search.typesen
- [With vue-instantsearch](#with-vue-instantsearch)
- [With angular-instantsearch](#with-angular-instantsearch)
- [Widget Specific Instructions](#widget-specific-instructions)
- [Caching](#caching)
- [Compatibility](#compatibility)
- [Development](#development)
- [Help](#help)
Expand Down Expand Up @@ -636,6 +637,46 @@ search = instantsearch({
});
```

## Caching

There are two modes of caching:

1. **Server-side caching:**

To enable server-side caching, add a parameter called `useServerSideSearchCache: true` in the `server` configuration block of the typesense-instantsearch-adapter like this:

```javascript
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
server: {
apiKey: "...",
nearestNode: {...},
nodes: [...],
useServerSideSearchCache: true // <<< Add this to send use_cache as a query parameter instead of post body parameter
},
additionalSearchParameters: {...}
});
```

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.

2. **Client-side caching:**

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:

```javascript
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
server: {
apiKey: "...",
nearestNode: {...},
nodes: [...],
cacheSearchResultsForSeconds: 2 * 60 // <<< Add this to configure the TTL for client-side cache in the browser
},
additionalSearchParameters: {...}
});
```



## Compatibility

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

0 comments on commit c9d38e2

Please sign in to comment.