@appolo/cache
Advanced tools
Comparing version 7.0.4 to 7.0.5
@@ -6,2 +6,3 @@ "use strict"; | ||
const appolo_cache_1 = require("appolo-cache"); | ||
const _ = require("lodash"); | ||
const ResultSymbol = "@result"; | ||
@@ -124,4 +125,15 @@ let Cache = class Cache { | ||
_getRedisMaxAge() { | ||
return Math.floor((this._options.dbMaxAge || this._options.maxAge) / 1000); | ||
let age = Math.floor((this._options.dbMaxAge || this._options.maxAge) / 1000); | ||
if (this._options.randomAge) { | ||
age += _.random(0, this._options.randomAge); | ||
} | ||
return age; | ||
} | ||
_getMemoryMaxAge() { | ||
let age = this._options.maxAge; | ||
if (this._options.randomAge) { | ||
age += _.random(0, this._options.randomAge); | ||
} | ||
return age; | ||
} | ||
_getRedisKey(key) { | ||
@@ -165,3 +177,3 @@ if (typeof key != "string") { | ||
let dto = value && value.hasOwnProperty && value.hasOwnProperty(ResultSymbol) ? value : { [ResultSymbol]: value }; | ||
this._cache.set(key, this._options.clone ? JSON.stringify(dto) : dto, this._options.maxAge); | ||
this._cache.set(key, this._options.clone ? JSON.stringify(dto) : dto, this._getMemoryMaxAge()); | ||
} | ||
@@ -168,0 +180,0 @@ _setRedisValue(key, value) { |
@@ -5,2 +5,3 @@ import {define, initMethod, inject, injectLazy} from 'appolo'; | ||
import {ILogger} from "@appolo/logger"; | ||
import * as _ from "lodash"; | ||
import {IInnerCacheOptions, IOptions} from "./IOptions"; | ||
@@ -191,5 +192,21 @@ import Timer = NodeJS.Timer; | ||
private _getRedisMaxAge(): number { | ||
return Math.floor((this._options.dbMaxAge || this._options.maxAge) / 1000) | ||
let age = Math.floor((this._options.dbMaxAge || this._options.maxAge) / 1000); | ||
if (this._options.randomAge) { | ||
age += _.random(0, this._options.randomAge) | ||
} | ||
return age; | ||
} | ||
private _getMemoryMaxAge(): number { | ||
let age = this._options.maxAge | ||
if (this._options.randomAge) { | ||
age += _.random(0, this._options.randomAge) | ||
} | ||
return age | ||
} | ||
private _getRedisKey(key: any): string { | ||
@@ -253,3 +270,3 @@ if (typeof key != "string") { | ||
this._cache.set(key, this._options.clone ? JSON.stringify(dto) : dto, this._options.maxAge); | ||
this._cache.set(key, this._options.clone ? JSON.stringify(dto) : dto, this._getMemoryMaxAge()); | ||
} | ||
@@ -256,0 +273,0 @@ |
@@ -17,2 +17,3 @@ import {IModuleOptions} from 'appolo'; | ||
} | ||
@@ -49,2 +50,3 @@ | ||
cacheNull?: boolean | ||
randomAge?: number | ||
@@ -51,0 +53,0 @@ } |
{ | ||
"name": "@appolo/cache", | ||
"version": "7.0.4", | ||
"version": "7.0.5", | ||
"description": "appolo cache module", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45232
1160