Skip to content

Commit 8e6dd90

Browse files
committed
implement some santy checks, most logic still in python
1 parent e1dc4bd commit 8e6dd90

File tree

3 files changed

+56
-375
lines changed

3 files changed

+56
-375
lines changed

temporalcache.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ const expire = (options) => {
178178

179179
const _wrapped_function = (...args) => {
180180
const now = new Date();
181-
181+
const key = JSON.stringify(args);
182182
if (
183-
!cache.has(args) ||
183+
!cache.has(key) ||
184184
should_expire(
185185
last,
186186
now,
@@ -194,10 +194,10 @@ const expire = (options) => {
194194
)
195195
) {
196196
const val = foo(...args);
197-
cache[args] = val;
197+
cache.set(key, val);
198198
}
199199
last = now;
200-
return cache[args];
200+
return cache.get(key);
201201
};
202202
return _wrapped_function;
203203
};
@@ -233,15 +233,15 @@ const interval = (options) => {
233233
}
234234

235235
const _wrapper = (foo) => {
236-
let last = new Date();
236+
let last = new Date(0);
237237
const cache = new Map();
238238

239239
const _wrapped_function = (...args) => {
240240
const now = new Date();
241241

242242
if (
243243
(now - last) / 1000 >
244-
calc(seconds, minutes, hours, days, weeks, months, years)
244+
calc({ seconds, minutes, hours, days, weeks, months, years })
245245
) {
246246
const val = foo(...args);
247247
cache[args] = val;
@@ -276,4 +276,4 @@ module.exports = {
276276
interval_hourly,
277277
interval_daily,
278278
interval_monthly,
279-
};
279+
};

0 commit comments

Comments
 (0)