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

How to replace existing cached data for endpoint? #32

Open
AllanCochrane opened this issue Sep 29, 2022 · 0 comments
Open

How to replace existing cached data for endpoint? #32

AllanCochrane opened this issue Sep 29, 2022 · 0 comments

Comments

@AllanCochrane
Copy link

I would like to replace the existing data returned by a Redis-cached endpoint.

I have a background process that is given the key for the cache as generated by a call to getKey(), so I should be using the same key as apicache-plus does.

My issue is that the although the background process inserts new data into the cache, when the endpoint is hit again then no data is returned, it's as if the cacheObject does not contain the data:

Printing out the cache object that is stored by the initial cache of the endpoint gives:

[apicache] AC: cacheObject = { headers: { 'x-powered-by': 'Express', 'access-control-allow-origin': '*', 'content-type': 'application/json; charset=utf-8', etag: 'W/"a11-7HqZ9k3jIh29rVTC8CNeY8qUBTE"', 'cache-control': 'max-age=30, must-revalidate', vary: 'Accept-Encoding', 'content-encoding': 'br' }, 'data-extra-pttl': 238, status: 200, encoding: 'binary', 'data-token': 'a668dc91-4bca-42a0-8b46-7ddc467f2034', timestamp: 1664485660278, key: 'get/http://localhost/api/v1/dashboard/net?branch=baz&project=bar&user=foo{}' }

The endpoint returns the expected cache data.

But when I call apicache.set(key,data) with the same key as in the structure above then the cache object becomes:

[apicache] AC: cacheObject = {"key":"get/http://localhost/api/v1/dashboard/net?branch=baz&project=bar&user=foo{}","data":{"computedAt":1664485680700,"data":[{...}]}}

and the endpoint returns nothing at all.

The newly stored data doesn't have same shape as the data that was originally stored.

So, how should we use apicache.set() to update the cached data of an endpoint?

Thanks

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

1 participant