corgi/src/services/QCategoryCache.ts

25 lines
526 B
TypeScript

import { singleton } from '../decorators/singleton'
import { PuzzleCategory } from '../models/content/PuzzleCategory'
/**
* 用于缓存所有题目的分类
*/
@singleton
export class QCategoryCache {
private _cache:Map<string, string> = new Map()
public async init() {
this._cache = await PuzzleCategory.allCateMap()
}
/**
* 根据id获取分类名
* @param {string} id
* @return {string}
*/
public getType(id: string): string {
return this._cache.has(id)? this._cache.get(id) : ''
}
}