Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response caching #273

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Response caching #273

wants to merge 10 commits into from

Conversation

neel1996
Copy link
Member

@neel1996 neel1996 commented Jun 8, 2023

Initial requests without caching

image

After caching mock response

image

@neel1996 neel1996 added type/enhancement New feature or request area/api Mimock APIs labels Jun 8, 2023
@neel1996 neel1996 added this to the v0.0.3 milestone Jun 8, 2023
@neel1996 neel1996 self-assigned this Jun 8, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jun 8, 2023

Codecov Report

Patch coverage: 82.81% and project coverage change: -4.26 ⚠️

Comparison is base (a4f39ba) 93.99% compared to head (bfda260) 89.73%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #273      +/-   ##
============================================
- Coverage     93.99%   89.73%   -4.26%     
- Complexity      477      490      +13     
============================================
  Files            96      288     +192     
  Lines          1615     4044    +2429     
  Branches        122      495     +373     
============================================
+ Hits           1518     3629    +2111     
- Misses           56      359     +303     
- Partials         41       56      +15     
Impacted Files Coverage Δ
...om/arbindo/mimock/common/constants/CacheNames.java 0.00% <0.00%> (ø)
...ava/com/arbindo/mimock/entities/RequestHeader.java 100.00% <ø> (ø)
...indo/mimock/generic/GenericMockRequestService.java 98.55% <ø> (ø)
...manage/mimocks/service/MockActionsServiceImpl.java 86.20% <ø> (ø)
...rc/main/java/com/arbindo/mimock/entities/Mock.java 50.00% <44.44%> (-16.67%) ⬇️
...ck/manage/mimocks/service/helpers/CacheHelper.java 81.48% <81.48%> (ø)
...ain/java/com/arbindo/mimock/MimockApplication.java 92.85% <100.00%> (ø)
...com/arbindo/mimock/caching/CacheConfiguration.java 100.00% <100.00%> (ø)
...com/arbindo/mimock/caching/CustomKeyGenerator.java 100.00% <100.00%> (ø)
...age/mimocks/service/MockManagementServiceImpl.java 94.18% <100.00%> (+0.03%) ⬆️

... and 188 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@cypress
Copy link

cypress bot commented Jun 8, 2023

Passing run #54 ↗︎

0 17 0 0 Flakiness 0

Details:

Merge bfda260 into 0f727b8...
Project: mimock Commit: 085c61c128 ℹ️
Status: Passed Duration: 02:32 💡
Started: Jun 16, 2023 7:59 AM Ended: Jun 16, 2023 8:02 AM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

@neel1996
Copy link
Member Author

Caching & Eviction considerations

Caching

  • The mock response for existing mocks will be cached whenever a mock endpoint is invoked by a client. A unique hash will be generated using the following parameters to be used as the cache key

Route + Http method + Query param string + Request headers + Request body

  • When a new mock gets created, the same unique parameters mentioned above will be used to generate an unique hash for the key

Eviction

  • The cache will be evicted based on sliding expiry policy. The cache that has not been accessed for the past 60 minutes will be evicted
  • ** The entire cache will be evicted when a mock is updated or archived. The thought process behind this decision is that when the user updates an existing mock, then evicting the unique mock will not be possible if a client has already triggered the caching with a different set of request headers. This will lead to inconsistencies if we try to evict a cache based on the unique key generated from the mock fetched from the Database
E.g:

Let's assume "client-x" invokes a "mock_a" with the following request headers 

- Authorization
- Content-type
- Host

These headers will decide the cache key. However, it is not necessary for the mock stored in the DB to have the same set of headers if strict header matching is not enabled for the mock.

In this case, if the user updates "mock_a", then the eviction will not remove the mock data from the cache as the hashed key will be different. Hence, all the existing cache needs to be evicted to ensure consistency 

- Newly created mocks will be cached with an unique hash first and then stored into the DB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Mimock APIs type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants