mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-07-07 01:12:06 +08:00
代码格式化
This commit is contained in:
@ -2,58 +2,62 @@ function MemoryCache() {
|
||||
this.cache = {}
|
||||
this.size = 0
|
||||
}
|
||||
|
||||
MemoryCache.prototype.add = function(key, value, time, timeoutCallback) {
|
||||
|
||||
MemoryCache.prototype.add = function (key, value, time, timeoutCallback) {
|
||||
var old = this.cache[key]
|
||||
var instance = this
|
||||
|
||||
|
||||
var entry = {
|
||||
value: value,
|
||||
expire: time + Date.now(),
|
||||
timeout: setTimeout(function() {
|
||||
timeout: setTimeout(function () {
|
||||
instance.delete(key)
|
||||
return timeoutCallback && typeof timeoutCallback === 'function' && timeoutCallback(value, key)
|
||||
}, time)
|
||||
return (
|
||||
timeoutCallback &&
|
||||
typeof timeoutCallback === 'function' &&
|
||||
timeoutCallback(value, key)
|
||||
)
|
||||
}, time),
|
||||
}
|
||||
|
||||
|
||||
this.cache[key] = entry
|
||||
this.size = Object.keys(this.cache).length
|
||||
|
||||
|
||||
return entry
|
||||
}
|
||||
|
||||
MemoryCache.prototype.delete = function(key) {
|
||||
|
||||
MemoryCache.prototype.delete = function (key) {
|
||||
var entry = this.cache[key]
|
||||
|
||||
|
||||
if (entry) {
|
||||
clearTimeout(entry.timeout)
|
||||
}
|
||||
|
||||
|
||||
delete this.cache[key]
|
||||
|
||||
|
||||
this.size = Object.keys(this.cache).length
|
||||
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
MemoryCache.prototype.get = function(key) {
|
||||
|
||||
MemoryCache.prototype.get = function (key) {
|
||||
var entry = this.cache[key]
|
||||
|
||||
|
||||
return entry
|
||||
}
|
||||
|
||||
MemoryCache.prototype.getValue = function(key) {
|
||||
|
||||
MemoryCache.prototype.getValue = function (key) {
|
||||
var entry = this.get(key)
|
||||
|
||||
|
||||
return entry && entry.value
|
||||
}
|
||||
|
||||
MemoryCache.prototype.clear = function() {
|
||||
Object.keys(this.cache).forEach(function(key) {
|
||||
|
||||
MemoryCache.prototype.clear = function () {
|
||||
Object.keys(this.cache).forEach(function (key) {
|
||||
this.delete(key)
|
||||
}, this)
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
module.exports = MemoryCache
|
||||
|
||||
module.exports = MemoryCache
|
||||
|
Reference in New Issue
Block a user