1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16class TesterCache<T> { 17 private cacheInfo: Map<string, T>; 18 private static instance: TesterCache<any>; 19 20 private constructor() { 21 this.cacheInfo = new Map<string, T>(); 22 } 23 24 static getInstance<T>(): TesterCache<T> { 25 if (!this.instance) { 26 this.instance = new TesterCache<T>(); 27 } 28 return this.instance; 29 } 30 31 public delete(key: string) { 32 if (this.cacheInfo.has(key)) { 33 this.cacheInfo.delete(key); 34 } 35 } 36 37 public get(key: string) { 38 if (this.cacheInfo.has(key)) { 39 return this.cacheInfo.get(key); 40 } 41 return undefined; 42 } 43 44 public has(key: string) { 45 return this.cacheInfo.has(key); 46 } 47 48 public set(key: string, value: T) { 49 if (!this.cacheInfo.has(key)) { 50 this.cacheInfo.set(key, value); 51 } 52 } 53 54 public clear() { 55 this.cacheInfo.clear(); 56 } 57} 58 59export { TesterCache }; 60