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 default Cache-Control header to files router #4348

Closed
wants to merge 5 commits into from
Closed

add default Cache-Control header to files router #4348

wants to merge 5 commits into from

Conversation

zhxiaogg
Copy link

I find this issue: #1857 but the Cache-Control header is not yet implemented in the files router, so I add some simple code.

I think the header value should be configurable, but I'm not sure where to put it. Need help.

@codecov
Copy link

codecov bot commented Nov 14, 2017

Codecov Report

Merging #4348 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4348      +/-   ##
==========================================
- Coverage    92.7%   92.65%   -0.05%     
==========================================
  Files         118      118              
  Lines        8346     8351       +5     
==========================================
+ Hits         7737     7738       +1     
- Misses        609      613       +4
Impacted Files Coverage Δ
src/Options/Definitions.js 100% <ø> (ø) ⬆️
src/Routers/FilesRouter.js 98.94% <100%> (+0.05%) ⬆️
src/RestWrite.js 93.1% <0%> (-0.73%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 96.83% <0%> (-0.11%) ⬇️
src/Adapters/Auth/meetup.js 89.47% <0%> (+5.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8fd5f31...363e733. Read the comment docs.

@flovilmart
Copy link
Contributor

this should probably be exposed as a function / options upon initializing parse-server.

@zhxiaogg
Copy link
Author

@flovilmart I add a filesCacheControl option to Parser server start options.

The last failed test seems not related to my code, can you help me run the tests again?

@montymxb
Copy link
Contributor

@zhxiaogg just retriggered the last stage of the build, should be good in a moment.

@zhxiaogg
Copy link
Author

@montymxb @flovilmart can you help me reviewing it and can this be merged?

@@ -64,6 +64,8 @@ export interface ParseServerOptions {
webhookKey: ?string;
/* Key for your files */
fileKey: ?string;
/* Cache-Control header for files router */
filesCacheControl: ?string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: definitions are generated from this file, just add the default value after an run the script in resources/buildConfigDefinitions.js

Copy link
Contributor

@montymxb montymxb left a comment

Choose a reason for hiding this comment

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

Can you add this into the Advanced Options section of the README as well. We'll want to have this visibly documented.

Beyond that I really like this, nice bit of functionality.

@montymxb
Copy link
Contributor

Just to note someone pointed out that it might be handy to also have each file indicate it's own cache control as well. We don't need that for this PR, but it would be great to have macro/micro control on caching for files. Have the ability to set global cache control (this), and maybe later add the ability to have files indicate their own cache control as well to supersede the global (for particular cases as needed).

@montymxb
Copy link
Contributor

montymxb commented Dec 8, 2017

@zhxiaogg bump

@zhxiaogg
Copy link
Author

@montymxb @flovilmart Sorry for delayed update. I added a default value for the setting and also added it to the README.

@montymxb
Copy link
Contributor

montymxb commented Dec 11, 2017 via email

@@ -137,7 +137,8 @@ module.exports.ParseServerOptions = {
},
"filesCacheControl": {
"env": "PARSE_SERVER_FILES_CACHE_CONTROL",
"help": "Cache-Control header for files router"
"help": "Cache-Control header for files router",
"default": "public, max-age=86400"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want a default value here. Changing expected behavior by introducing caching would cause unexpected issues if someone needed to update their file within that 24 hr period. It would be best if it was unset as it was before.

@@ -232,6 +232,7 @@ The client keys used with Parse are no longer necessary with Parse Server. If yo
#### Advanced options

* `fileKey` - For migrated apps, this is necessary to provide access to files already hosted on Parse.
* `filesCacheControl` - Set `Cache-Control` header when serving files with builtin files router. Defaults to `public, max-age=86400` (1 day).
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this. Still not sure about the default value though...@flovilmart do you want to weigh in on this?

@@ -65,7 +65,7 @@ export interface ParseServerOptions {
/* Key for your files */
fileKey: ?string;
/* Cache-Control header for files router */
filesCacheControl: ?string;
filesCacheControl: ?string; // = public, max-age=86400
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, if we drop the default we'll want to remove this comment.

Copy link
Contributor

@montymxb montymxb left a comment

Choose a reason for hiding this comment

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

Overall looks good with adding in the Advanced Options category. Not entirely onboard with setting the default value though. Waiting to see what @flovilmart thinks of this.

@flovilmart
Copy link
Contributor

I’d like to keep the defaults empty as well, also most of the files should be served by a 3rd party (S3 etc..) how does this apply on those cases?

@flovilmart
Copy link
Contributor

Closing, as having many conflicts, please reopen and address all the concerns.

@flovilmart flovilmart closed this Aug 7, 2018
@vamsi27
Copy link

vamsi27 commented Nov 6, 2019

Closing, as having many conflicts, please reopen and address all the concerns.

are there any plans to include caching of files in the roadmap?

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.

None yet

4 participants