Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Add expiration to cache entry #21

Merged
merged 3 commits into from
Apr 13, 2021
Merged

Conversation

madsodgaard
Copy link
Contributor

@madsodgaard madsodgaard commented Apr 12, 2021

  • Adds expiration functionality recently added to the Vapor Cache to prevent the cache being filled up with stale values, such as old rate-limiting keys.
  • Allows customization of the error thrown if they client is sending too many requests:
req.gatekeeper.gatekeeper(on: req, throwing: MyError())
GatekeeperMiddleware(error: MyError())
  • Fixes an issue where effectively even if the config was 5 requests per second, the client would only really have 4 request available and be rate-limited on the 5th. They are now correctly first rate-limited on request no. 6.

Copy link
Contributor

@siemensikkema siemensikkema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a small remark. I’ll pre-approve :)

Sources/Gatekeeper/Gatekeeper.swift Outdated Show resolved Hide resolved
@siemensikkema siemensikkema merged commit 02ec165 into ml-archive:master Apr 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants