diff --git a/apps/server/src/modules/school/api/test/school-users.api.spec.ts b/apps/server/src/modules/school/api/test/school-users.api.spec.ts index f514c9468bc..2c02af91a27 100644 --- a/apps/server/src/modules/school/api/test/school-users.api.spec.ts +++ b/apps/server/src/modules/school/api/test/school-users.api.spec.ts @@ -29,7 +29,8 @@ describe('School Controller (API)', () => { beforeEach(async () => { await cleanupCollections(em); - await em.clearCache('roles-cache-teacher'); + await em.clearCache('roles-cache-byname-teacher'); + await em.clearCache('roles-cache-bynames-teacher'); }); afterAll(async () => { diff --git a/apps/server/src/shared/repo/role/role.repo.integration.spec.ts b/apps/server/src/shared/repo/role/role.repo.integration.spec.ts index 91b2a083fff..91df9f230a7 100644 --- a/apps/server/src/shared/repo/role/role.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/role/role.repo.integration.spec.ts @@ -148,4 +148,18 @@ describe('role repo', () => { expect(result).toContainEqual(roleB); }); }); + + describe('roles cache', () => { + it('should successfully use different caches in sequence', async () => { + const roleA = roleFactory.build(); + const roleB = roleFactory.build(); + + await em.persistAndFlush([roleA, roleB]); + + const firstResult = await repo.findByName(roleA.name); + expect(firstResult).toEqual(roleA); + const secondResult = await repo.findByNames([roleA.name]); + expect(secondResult).toEqual([roleA]); + }); + }); }); diff --git a/apps/server/src/shared/repo/role/role.repo.ts b/apps/server/src/shared/repo/role/role.repo.ts index 02527a4bfb2..e11e6615fda 100644 --- a/apps/server/src/shared/repo/role/role.repo.ts +++ b/apps/server/src/shared/repo/role/role.repo.ts @@ -16,7 +16,7 @@ export class RoleRepo extends BaseRepo { const promise: Promise = this._em.findOneOrFail( Role, { name }, - { cache: [`roles-cache-${name}`, this.cacheExpiration] } + { cache: [`roles-cache-byname-${name}`, this.cacheExpiration] } ); return promise; } @@ -30,7 +30,7 @@ export class RoleRepo extends BaseRepo { const promise: Promise = this._em.find( Role, { name: { $in: names } }, - { cache: [`roles-cache-${names.join('-')}`, this.cacheExpiration] } + { cache: [`roles-cache-bynames-${names.join('-')}`, this.cacheExpiration] } ); return promise; }