This message was deleted.
# community-help
s
This message was deleted.
k
Cache is not enabled by default. This is for the typesense server.
j
I have a problem with the following scenario 1. Woo updates ts 2. Once update successfull 3. woo then send a revalidation request to our next app 4. next app queries data to ts but the problem is the cache. The response is a cache version. so I am checking if there is a way to use the search without getting cache response
I can see cache_ttl is 60 seconds. by then next tries to regenerate the page but since it is within 60 seconds it generates a cache page.
k
Unless you set a cache paramter to your search request we don't cache anything.
Are you querying a single node or cluster?
j
yes I single cluster.
even in my local dev it shows the cache data unless 60 seconds passes after the ts data update
k
What client are you using?
j
typesense client
k
That's the server
j
sorry. I thought that's the client. I was using that for getting data using the search method
im pretty sure I am using that. I thought that is the typesense client.
k
What language are you using?
j
js
with react
k
Maybe you can post a small example that reproduces the issue.
j
that would be hard. ahahha
@Kishore Nallan i really think it is affected by cache_ttl
k
It's difficult for me to debug without a reproduceable example. If it's just a cache TTL related issue then it should be easy to reproduce as a standalone example.
j
you need the query right?
k
No, a small example program where you create a collection, index data and query it to show how the data is not reflecting the update
j
it would be hard for me because the update is from woo. What I can do is show you a video. detailing the steps. Would that help?
k
What happens if you added a sleep of 5 seconds to your next app query? Does it only work if you wait 60 seconds exactly?
j
i can't say its exactly 60 seconds because what I do is 1. run next.js app on dev env and visit a product. 2. update the product with small change 3. then i reload the dev page i open in step 1 4. page is not updated 5. wait for a minute 6. reload the product page again. This time it will show the updated data
k
Instead of waiting for 1 min can you try refreshing after few seconds?
j
yeah okay
k
Also check typesense log to see what happens in that interval
j
how can I see ts log?
k
How are you running Typensese?
j
your service. Cloud typesense
k
On cloud that's not possible but you said you can reproduce this locally right? For local also you are using cloud?
j
I did reload the page after i updated woo. a few times and it did not update right away
k
Please DM me your cluster ID
j
yes for my local site I am using cloud api keys
k
Your cluster looks fine. Are you making a query directly from your JS in the browser or through your backend node.js?
j
I believe next.js getStaticProps is a node.js.
k
Are you sure there are no other caches anywhere else in your app
Can you paste the exact query your app sends to typesense?
j
inside the get static props I use typesense libaray to get the data.
k
If it's made from frontend, you can get it from network inspect on your browser console.
j
this is the search params codes I have.
Copy code
const getProductBySlug = async (sku: string): Promise<ITSProduct | null> => {
    let searchParameters = {
        q: '*',
        query_by: 'slug',
        filter_by: `slug:=[${sku}]`,
        sort_by: '_text_match:desc',
        facet_by: 'slug',
    };

    const results = await client
        .collections(TS_CONFIG.collectionNames.product)
        .documents()
        .search(searchParameters);

    let found = null;
    if (typeof results.hits !== 'undefined' && results.hits[0]) {
        const tsProductData: ITSProduct = JSON.parse(
            JSON.stringify(results.hits[0].document)
        );
        return tsProductData;
    }
    return found;
};
its not in the froned since it is done via getstaticprops.
how can I log the query using your ts library?
k
Can you show me how
client
is initialized?
j
This is how we initialize it.
Copy code
import { Client } from 'typesense';
import TS_CONFIG from './config';

const c = new Client(TS_CONFIG.server);

export default c;
give me a sec i'll get you the ts_config
Copy code
const TS_CONFIG = {
    server: {
        apiKey: process.env.NEXT_PUBLIC_TS_APIKEY as string, // Be sure to use an API key that only allows search operations
        nodes: [
            {
                host: process.env.NEXT_PUBLIC_TS_HOST as string,
                path: '', // Optional. Example: If you have your typesense mounted in localhost:8108/typesense, path should be equal to '/typesense'
                port: 443,
                protocol: 'https',
            },
        ],
    },
    collectionNames: {
        product: `product-${process.env.NEXT_PUBLIC_TS_STORE_ID}`,
        taxonomy: `taxonomy-${process.env.NEXT_PUBLIC_TS_STORE_ID}`,
        page: `page-${process.env.NEXT_PUBLIC_TS_STORE_ID}`,
    },
};

export default TS_CONFIG;
this is the TS_CONFIG
k
Can you try adding
cacheSearchResultsForSeconds: 0
after
apiKey
j
okay testing now
yes it works immediately
k
Ok so the JS client alone seems to have this configuration but according to this comment it is disabled by default: https://github.com/typesense/typesense-js/issues/52#issuecomment-834863277
Are you using instantsearch adapter?
j
yes for the actual website search but for this query no need to use it.
k
Somehow it was being enabled. Will take a look, but your problem is now solved, correct?
j
yeah I just need to disable it on this query
l
hi guys, I saw this trend and I am also implementing caching in my search, but I defined it within my search preset, using the query parameters, is it necessary to put it also in the client initialization to work correctly, from what I saw here? I got this doubt now
I am setting the search parameters here and using as preset in my code
j
That might just work. Laura.
k
The Instant search adapter has a client level cache. That's what the client level initialisation param enables.
What you define in search preset is server side caching.
l
Okay, so from what I understand, I am implementing the caching only on the server side with the search parameters, but I also need to implement it on the client side in my typesense initialization in the code?
k
You can do either or both as per your requirement 🙂
l
Okay! Thanks