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

Add caching #54

Merged
merged 5 commits into from
Sep 17, 2021
Merged

Add caching #54

merged 5 commits into from
Sep 17, 2021

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Aug 18, 2021

  1. Caches the serialization result

Uses the jsonapi-serializer feature for caching that uses the configured Rails cache store.

Never expire the records because page and element records have a cache_key that is updated by alchemy in the correct way.

  1. Adds HTTP caching

Uses conditional get for loading page(s) only when necessary from the database. If the browser cache is still fresh we return a 304 instead.

Uses the jsonapi-serializer feature for caching that uses the configured
Rails cache store.

Never expire the records because page and element records have a cache_key
that is updated by alchemy in the correct way.
@tvdeyen tvdeyen force-pushed the add-caching branch 2 times, most recently from 04d6cf5 to 1915ab4 Compare August 19, 2021 11:13
@tvdeyen tvdeyen requested a review from mamhoff August 19, 2021 11:24
@tvdeyen tvdeyen changed the title Add caching to page and element serializers Add caching Aug 19, 2021
@tvdeyen tvdeyen marked this pull request as ready for review August 19, 2021 11:25
@mamhoff
Copy link
Contributor

mamhoff commented Aug 26, 2021

I think the Alchemy branch this references needs to be changed to main.

mamhoff
mamhoff previously approved these changes Aug 26, 2021
Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

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

Works really well, I couldn't break it.
Here's what I tried:
For both index and show actions:

Load page -> 200
Load it again -> 304
Change it -> 304 (page not published!)
Publish it -> 200
Load it again -> 304
Change params -> 200
Load it again with changed params -> 304

The internet is great.

@tvdeyen
Copy link
Member Author

tvdeyen commented Aug 26, 2021

Works really well, I couldn't break it.
Here's what I tried:
For both index and show actions:

Load page -> 200
Load it again -> 304
Change it -> 304 (page not published!)
Publish it -> 200
Load it again -> 304
Change params -> 200
Load it again with changed params -> 304

Thanks. Have you tried the admin and layoutpages routes as well?
Admin routes should change on update rather than publish.
Same schema applies to the layoutpages as well.

The internet is great.

Yay, HTTP Caching. Take that GraphQL

Prevents the database from loading all content if the
page is still fresh and the browser can use its cache
Only loads pages and all includes if the page is stale,
otherwise it returns a 304 calculated by the latest published
page published_at value.
If we want to be able to use CDNs we need to set public
cache headers and a expiration duration.

The expiration defaults to 3 hours but you can set a

    ALCHEMY_JSON_API_CACHE_DURATION

variable to any integer.
@tvdeyen tvdeyen dismissed mamhoff’s stale review September 10, 2021 14:48

Implemented public cache headers

@tvdeyen tvdeyen merged commit 3218ee4 into main Sep 17, 2021
@tvdeyen tvdeyen deleted the add-caching branch September 17, 2021 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants