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

PATCH returns cached response #407

Open
darrenjennings opened this issue Jan 30, 2020 · 1 comment
Open

PATCH returns cached response #407

darrenjennings opened this issue Jan 30, 2020 · 1 comment

Comments

@darrenjennings
Copy link

darrenjennings commented Jan 30, 2020

It looks like GET requests are cached, so when performing a PATCH request, it modifies the db row, but then returns the result from cache.

// TypeOrmModuleOptions
cache: {
    type: 'redis',
    options: {
      host: process.env.REDIS_HOST,
      port: +process.env.REDIS_PORT,
      duration: 10000,
    },
    alwaysEnabled: true,
  },
// user.entity.ts
@Crud({
  model: {
    type: User,
  },
  params: {
    id: {
      field: 'id',
      type: 'string',
      primary: true,
    },
  },
  query: {
    cache: 3000
▶ http PATCH :3000/api/users/f333c88b-46ae-436b-b91b-a8994bf8aa35 isActive:=false
HTTP/1.1 200 OK
{
    ...
    "isActive": false,
    ...
}

~
▶ http PATCH :3000/api/users/f333c88b-46ae-436b-b91b-a8994bf8aa35 isActive:=true
HTTP/1.1 200 OK
{
    ...
    "isActive": false, <-- this should be true, but is returned from cache
    ...
}

~
▶ http GET :3000/api/users/f333c88b-46ae-436b-b91b-a8994bf8aa35
HTTP/1.1 200 OK
{
    ...
    "isActive": true,
    ...
}

PUT seems to not be affected by this issue.

@rewiko
Copy link
Collaborator

rewiko commented Apr 3, 2021

Hello,

Indeed I got the same issue, when update or delete the code get the resource first, then update or delete it and get the resource again. The cache should only be use for HTTP GET method.

I created a PR to solve the issue.

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

2 participants