1/* 2 * Copyright (c) 2024 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 */ 15class Cache { 16 private cacheInfo: Map<string, Object>; 17 18 constructor() { 19 this.cacheInfo = new Map<string, Object>(); 20 } 21 22 public delete(key: string) { } 23 24 public get(key: string) { 25 if (this.cacheInfo.has(key)) { 26 return this.cacheInfo.get(key); 27 } 28 return undefined; 29 } 30 31 public has(key: string) { } 32 33 public set(key: string, value: any) { 34 if (this.cacheInfo.has(key)) { 35 this.cacheInfo.set(key, value); 36 } 37 } 38} 39 40class CacheInCacheStoreManager { 41 cache: Map<string, object>; 42 43 constructor() { 44 this.cache = new Map<string, object>(); 45 } 46 47 public getCache(key: string): object { 48 return this.cache.get(key); 49 } 50 51 public setCache(key: string, value: object): void { 52 this.cache.set(key, value); 53 } 54} 55 56class CacheStoreManager { 57 cacheInCacheStoreManager: Map<string, CacheInCacheStoreManager>; 58 59 constructor() { 60 this.cacheInCacheStoreManager = new Map<string, CacheInCacheStoreManager>(); 61 } 62 63 public mount(cacheStoreManagerKey: string): CacheInCacheStoreManager { 64 let cacheInCacheStoreManagerValue: CacheInCacheStoreManager | undefined = 65 this.cacheInCacheStoreManager.get(cacheStoreManagerKey); 66 67 if (!cacheInCacheStoreManagerValue) { 68 cacheInCacheStoreManagerValue = new CacheInCacheStoreManager(); 69 this.cacheInCacheStoreManager.set(cacheStoreManagerKey, cacheInCacheStoreManagerValue); 70 } 71 72 return cacheInCacheStoreManagerValue; 73 } 74 75 public unmount(cacheStoreManagerKey: string): void { 76 this.cacheInCacheStoreManager?.delete(cacheStoreManagerKey); 77 } 78 79 public keys(): IterableIterator<string> { 80 return this.cacheInCacheStoreManager?.keys(); 81 } 82} 83 84export { 85 Cache, 86 CacheInCacheStoreManager, 87 CacheStoreManager 88}