Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this? (check all applicable)
Description
When a new article was created, then the existing
articles
cache was not getting flushed. Because of which, newly created article was not showing up in the response until that stale cache was purged by some other action.Proposed Solution
Added different callbacks which performs under various stages of
article
lifecycle to purge cache data and maintain consistency.after_create
- it invokes:purge_all
and clears existing cache collection. So that, next request would hit server and stores fresh copy of data as cache.after_save
- It invokes:purge
and purges only itself from cache collection. (like, when an article gets updated)after_destroy
- It invokes both:purge
and:purge_all
clearing record and also the collection holding that record.Article creation, updation and destruction happens at different parts of application. In order to stay consistent, attached these purge actions to activerecord callbacks.
Related Tickets & Documents
This PR is related to issue #6417
QA Instructions, Screenshots, Recordings
NOTE
- It is not possible to test the functionality in local environment. We need to deploy to live server to verify the changes.Steps to validate:
x-cache: MISS
in its response headers.x-cache: HIT
as it is served from cache.surrogate_key
inside response headers will respond to cache miss/hit. Rest all endpoints related to articles will always containx-cache: MISS
.surrogate_key
in response headers are...https://dev.to/api/articles
https://dev.to/api/articles/:id
https://dev.to/api/articles/:slug
Added/updated tests?
have not been included
[Forem core team only] How will this change be communicated?
Will this PR introduce a change that impacts Forem members or creators, the
development process, or any of our internal teams? If so, please note how you
will share this change with the people who need to know about it.
Storybook (for Crayons components)
updated. I have filled out the
Changes Requested
issue template so Community Success can help update the Admin Docs
appropriately.
CHANGELOG.md
or in a forem.dev post
replace this line with details on why this change doesn't need to be
shared
Are there any post deployment tasks we need to perform?
Yup, validating this fix. Making sure data is purged after creation/updation/destruction of an article by monitoring
x-cache
key of the request(s) made to those endpoints which set and deliversurrogate_key
inside response headers.