Skip to content

PATCH returns cached response  #407

Open
@darrenjennings

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions