Skip to content

Commit

Permalink
Merge pull request #62 from neumanf/refactor/rate-limiting
Browse files Browse the repository at this point in the history
refactor: use ehcache instead of hazelcast for rate limiting
  • Loading branch information
neumanf authored Aug 31, 2024
2 parents 6ee1616 + 080367e commit b1b30a6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 83 deletions.
41 changes: 0 additions & 41 deletions apps/api/fly.toml

This file was deleted.

16 changes: 3 additions & 13 deletions apps/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,9 @@
<version>0.12.0</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<classifier>jakarta</classifier>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
19 changes: 13 additions & 6 deletions apps/api/src/main/resources/application.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ spring:

cache:
jcache:
provider: com.hazelcast.cache.impl.HazelcastServerCachingProvider
config: classpath:hazelcast.xml
config: classpath:ehcache.xml

security:
oauth2:
Expand All @@ -30,40 +29,48 @@ bucket4j:
cache-name: buckets
http-response-body: '{ "status": "error", "message": "Too many requests", "data": null, "errors": [] }'
url: /url-shortener/redirect/.*
http-response-headers:
Access-Control-Allow-Origin: ${FRONTEND_URL}
rate-limits:
- cache-key: getRemoteAddr()
bandwidths:
- capacity: 20
- capacity: 50
time: 1
unit: minutes
- id: url_shortener_shorten
cache-name: buckets
http-response-body: '{ "status": "error", "message": "Too many requests", "data": null, "errors": [] }'
url: /url-shortener/shorten
http-response-headers:
Access-Control-Allow-Origin: ${FRONTEND_URL}
rate-limits:
- cache-key: getRemoteAddr()
bandwidths:
- capacity: 10
- capacity: 30
time: 1
unit: hours
- id: pastebin_get_paste
cache-name: buckets
http-response-body: '{ "status": "error", "message": "Too many requests", "data": null, "errors": [] }'
url: /pastebin/paste/.*
http-response-headers:
Access-Control-Allow-Origin: ${FRONTEND_URL}
rate-limits:
- cache-key: getRemoteAddr()
bandwidths:
- capacity: 20
- capacity: 50
time: 1
unit: minutes
- id: pastebin_paste
cache-name: buckets
http-response-body: '{ "status": "error", "message": "Too many requests", "data": null, "errors": [] }'
url: /url-shortener/shorten
http-response-headers:
Access-Control-Allow-Origin: ${FRONTEND_URL}
rate-limits:
- cache-key: getRemoteAddr()
bandwidths:
- capacity: 10
- capacity: 30
time: 1
unit: hours

Expand Down
3 changes: 1 addition & 2 deletions apps/api/src/main/resources/application.testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ spring:

cache:
jcache:
provider: com.hazelcast.cache.impl.HazelcastServerCachingProvider
config: classpath:hazelcast.xml
config: classpath:ehcache.xml

security:
oauth2:
Expand Down
3 changes: 1 addition & 2 deletions apps/api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ spring:

cache:
jcache:
provider: com.hazelcast.cache.impl.HazelcastServerCachingProvider
config: classpath:hazelcast.xml
config: classpath:ehcache.xml

security:
oauth2:
Expand Down
17 changes: 17 additions & 0 deletions apps/api/src/main/resources/ehcache.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<config xmlns='http://www.ehcache.org/v3'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
<cache alias="buckets">
<expiry>
<ttl unit="seconds">3600</ttl>
</expiry>
<heap unit="entries">1000000</heap>
<jsr107:mbeans enable-statistics="true"/>
</cache>
<cache alias="filterConfigCache">
<heap unit="entries">1000000</heap>
<jsr107:mbeans enable-statistics="true"/>
</cache>
</config>
19 changes: 0 additions & 19 deletions apps/api/src/main/resources/hazelcast.xml

This file was deleted.

0 comments on commit b1b30a6

Please sign in to comment.