Skip to content

Commit

Permalink
chore: Change ttl argument to expiresAt in cache implementation (#…
Browse files Browse the repository at this point in the history
…218)

To align with local rate limiting in #205
  • Loading branch information
blaine-arcjet authored Feb 9, 2024
1 parent 83a3a8c commit 0414e10
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions arcjet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class Cache<T> {
}
}

set(key: string, value: T, ttl: number) {
this.expires.set(key, nowInSeconds() + ttl);
set(key: string, value: T, expiresAt: number) {
this.expires.set(key, expiresAt);
this.data.set(key, value);
}

Expand Down Expand Up @@ -1165,6 +1165,7 @@ export default function arcjet<
fingerprint,
path: details.path,
runtime: runtime(),
ttl: results[idx].ttl,
conclusion: results[idx].conclusion,
reason: results[idx].reason,
});
Expand Down Expand Up @@ -1209,7 +1210,11 @@ export default function arcjet<
reason: decision.reason,
});

blockCache.set(fingerprint, decision.reason, decision.ttl);
blockCache.set(
fingerprint,
decision.reason,
nowInSeconds() + decision.ttl,
);
}

return decision;
Expand Down Expand Up @@ -1241,7 +1246,11 @@ export default function arcjet<
decision.ttl,
);

blockCache.set(fingerprint, decision.reason, decision.ttl);
blockCache.set(
fingerprint,
decision.reason,
nowInSeconds() + decision.ttl,
);
}

return decision;
Expand Down

0 comments on commit 0414e10

Please sign in to comment.