Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/main/core/src/lib/cache/storage/ |
Upload File : |
import type {ICacheStorage} from './i-cache-storage'; import Type from '../../type'; export default class LsStorage implements ICacheStorage { stackKey = 'BX.Cache.Storage.LsStorage.stack'; stack = null; /** * @private */ getStack(): {[key: string]: any} { if (Type.isPlainObject(this.stack)) { return this.stack; } const stack = localStorage.getItem(this.stackKey); if (Type.isString(stack) && stack !== '') { const parsedStack = JSON.parse(stack); if (Type.isPlainObject(parsedStack)) { this.stack = parsedStack; return this.stack; } } this.stack = {}; return this.stack; } /** * @private */ saveStack() { if (Type.isPlainObject(this.stack)) { const preparedStack = JSON.stringify(this.stack); localStorage.setItem(this.stackKey, preparedStack); } } get(key: string) { const stack = this.getStack(); return stack[key]; } set(key: string, value: any) { const stack = this.getStack(); stack[key] = value; this.saveStack(); } delete(key: string) { const stack = this.getStack(); if (key in stack) { delete stack[key]; } } has(key: string): boolean { const stack = this.getStack(); return key in stack; } get size(): number { const stack = this.getStack(); return Object.keys(stack).length; } keys(): Array<string> { const stack = this.getStack(); return Object.keys(stack); } values(): Array<any> { const stack = this.getStack(); return Object.values(stack); } }