Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to tell if the result comes from a cache hit or miss? #142

Open
ligreman opened this issue Apr 10, 2024 · 4 comments
Open

Comments

@ligreman
Copy link

ligreman commented Apr 10, 2024

First of all thanks for this great plugin.

I'm using it to cache some database searchs and I want to answer the clients with a X-Cache-Status header that informs if the data was taken from cache or from database (header values Hit or Miss).

cache.define('fetchSomething', async (k) => {
  return { k }
})

fastify.get('/foo', async function (request, reply) {
        const p1 = await cache.fetchSomething(42)

        // If p1 comes from a cache Hit, set reply header[X-Cache-Status] to Hit. Else Miss.

        return reply.send({msg: 'Hello'});
    });

Is there a way to tell if the result of fetchSomething comes from the cache (Hit) or from database (Miss)? I've been struggling with the onHit, onMiss... events but they only receive the key as parameter.

Thanks!

@mcollina
Copy link
Owner

Actually it would be a great feature to add (maybe behind an option).

@MyNameIsNeXTSTEP
Copy link

Hi, @mcollina !
Is this project still maintained and developed by you ?
The last release was 7mth ago though.

I'd like to help with this issue and contribute, but I'm not sure if the project is going to be taken further or not.

@MyNameIsNeXTSTEP
Copy link

I see here another collaborator @simone-sanfratello, hi!
Can you answer my question above too please.

@mcollina
Copy link
Owner

mcollina commented Dec 7, 2024

@MyNameIsNeXTSTEP this project is maintained. It's in a stable state and I use it kind of everywhere. However it works well for me, so you might not see many new features coming unless I receive a PR.

(My github notifications are very busy, sorry for the delay waiting, a PR to fix would be amazing!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants