4

我有一个服务类create,list,以及update修改实体的方法

我在列表方法中设置了redis缓存,缓存键是list_cache_1,list_cache_2,...

我的问题是,如何删除createupdate方法中的所有相关缓存,例如

this.connection.queryResultCache.remove([`list_cache:*`]);
4

1 回答 1

0

when you set a "cache id" via QueryBuilder:

const users = await connection
    .createQueryBuilder(User, "user")
    .where("user.isAdmin = :isAdmin", { isAdmin: true })
    .cache("list_cache_1", 25000)
    .getMany();

Or with Repository:

const users = await connection
    .getRepository(User)
    .find({
        where: { isAdmin: true },
        cache: {
            id: "list_cache_1",
            milliseconds: 25000
        }
    });

then, get the connection object and remove as below

import { getConnection } from "typeorm";

const connection = getConnection();
await connection.queryResultCache.remove([`list_cache_1`]);

however, i'm not aware of a typeorm method to remove list_cache_* with wildcard.

于 2020-06-23T00:55:08.397 回答