BetterDiscordApp-v2/client/src/modules/cache.js

39 lines
963 B
JavaScript
Raw Normal View History

2018-08-12 16:40:26 +02:00
/**
* BetterDiscord Cache Module
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const CACHE = [];
2018-08-12 17:10:22 +02:00
2018-08-12 16:40:26 +02:00
export default class Cache {
static get cache() {
return CACHE;
}
2018-08-12 17:10:22 +02:00
/**
2018-08-12 17:37:11 +02:00
* Push something to cache
2018-08-12 17:10:22 +02:00
* @param {String} where Cache identifier
* @param {any} data Data to push
*/
2018-08-12 16:40:26 +02:00
static push(where, data) {
if (!this.cache[where]) this.cache[where] = [];
this.cache[where].push(data);
}
2018-08-12 17:10:22 +02:00
/**
* Find something in cache
* @param {String} where Cache identifier
* @param {Function} what Find callback
*/
2018-08-12 16:40:26 +02:00
static find(where, what) {
if (!this.cache[where]) this.cache[where] = [];
return this.cache[where].find(what);
}
}