Skip to content

Commit

Permalink
Remote Avatar 데코레이션용 캐시
Browse files Browse the repository at this point in the history
  • Loading branch information
yunochi committed Jun 4, 2024
1 parent 00869aa commit 4a5fcfe
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/backend/src/core/AvatarDecorationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {IsNull} from "typeorm";
@Injectable()
export class AvatarDecorationService implements OnApplicationShutdown {
public cache: MemorySingleCache<MiAvatarDecoration[]>;
public cacheWithRemote: MemorySingleCache<MiAvatarDecoration[]>;

constructor(
@Inject(DI.config)
Expand All @@ -44,6 +45,7 @@ export class AvatarDecorationService implements OnApplicationShutdown {
private httpRequestService: HttpRequestService,
) {
this.cache = new MemorySingleCache<MiAvatarDecoration[]>(1000 * 60 * 30);
this.cacheWithRemote = new MemorySingleCache<MiAvatarDecoration[]>(1000 * 60 * 30);

this.redisForSub.on('message', this.onMessage);
}
Expand Down Expand Up @@ -177,8 +179,10 @@ export class AvatarDecorationService implements OnApplicationShutdown {
};
if (existingDecoration == null) {
await this.create(decorationData);
this.cacheWithRemote.delete();
} else {
await this.update(existingDecoration.id, decorationData);
this.cacheWithRemote.delete();
}
const findDecoration = await this.avatarDecorationsRepository.findOneBy({
host: userHost,
Expand Down Expand Up @@ -212,11 +216,12 @@ export class AvatarDecorationService implements OnApplicationShutdown {
public async getAll(noCache = false, withRemote = false): Promise<MiAvatarDecoration[]> {
if (noCache) {
this.cache.delete();
this.cacheWithRemote.delete();
}
if (!withRemote) {
return this.cache.fetch(() => this.avatarDecorationsRepository.find({ where: { host: IsNull() } }));
} else {
return this.cache.fetch(() => this.avatarDecorationsRepository.find());
return this.cacheWithRemote.fetch(() => this.avatarDecorationsRepository.find());
}
}

Expand Down

0 comments on commit 4a5fcfe

Please sign in to comment.