#community-help

Typesense Pagination and Caching Concerns

TLDR Michal expressed concerns about Typesense costs and pagination for an infinite scroll app. Kishore Nallan suggested fetching 250 results upfront and mentioned Typesense doesn't cache per page result sets.

Powered by Struct AI
11
8mo
Solved
Join the chat
Feb 05, 2023 (8 months ago)
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
12:50 PM
Hello, I am worried about the costs associated with Typesense. Regarding pagination, is retrieval of the subsequent pages in a search considered separate requests, or are they retrieved from a cache created by the initial search?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:56 PM
> Hello, I am worried about the costs associated with Typesense.
Can you elaborate?
12:57
Kishore Nallan
12:57 PM
We don't cache result set from previous pages.
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
01:04 PM
I'd like to use Typesense for full-text search and expensive quering. I have an app with an infinite scrolling list and would like to request the next batch of 10 results as a user scrolls down. Making an expensive query every time seems very expensive and wasteful so I'd like to make subsequent calls to cache instead.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:05 PM
I agree that this can be optimized, but caching will introduce some complexities around cache busting due to writes etc.

For now, you can fetch 250 results upfront and then do in-app pagination.
01:06
Kishore Nallan
01:06 PM
When you do a search, Typesense anyway operates on a minimum working set of 256 hits, so this won't be slower (except for fetching 256 records at once, which should be fine unless docs are huge)
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
01:17 PM
Oh okay, so to retrieve the next page, Should I make a request every time the user scrolls down 256 documents?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:25 PM
Yes but note that deep pagination does impact performance.
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
01:31 PM
yes, that is also my concern. If i set the use_cache flag to true, would that fetch subsequent pages on the same query from cache, or do I have to over-fetch let's say 1000 records and implement my own caching solution?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:34 PM
Use cache only caches whole results, not per page result set
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
01:39 PM
I understand. Thank you. I think this might be okay for full-text search but when running an expensive query that's not fully indexable this might be expensive without caching.