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.
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
feat: add permanent environment document cache #5187
base: main
Are you sure you want to change the base?
feat: add permanent environment document cache #5187
Changes from 1 commit
f18d0d7
b9ef7a2
6ab3b22
f134ebe
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between
EXPIRE_ENVIRONMENT_DOCUMENT_CACHE=False
andCACHE_ENVIRONMENT_DOCUMENT_TIMEOUT=0
? Also, why change a good name (_SECONDS suffix) to a worse one?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, technically, lots! See here - they're distinct opposites. If we were to assume that
0
meant cache indefinitely then we'd be completely changing the default behaviour (which is to not cache at all). Admittedly, we have logic elsewhere in the app that only inspects the cache if the value is greater than 0 (see here), so we could modify that to our will, but I'd rather keep it such that the settings make sense on their own.Yeah, this is a good question. My logic here was that
None
is now a valid value for the variable which, to me, meant that_TIMEOUT
made more sense - I don't feel particularly strongly about this though. Note that I did not change the environment variable name, only the setting.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've come up with the following options to consider:
-1
as aCACHE_ENVIRONMENT_DOCUMENT_SECONDS
value that means "never expire the cache". This will simplify business logic and hopefully ease cognitive load. We have a lot of settings already!CACHE_ENVIRONMENT_DOCUMENT_MODE: Literal["PERSISTENT", "EXPIRING"] = env.str(default="EXPIRING")
. This introduces a new setting but it's more expressive and easy to understand.In any case, I expect the new/modified settings to be reflected in the docs.
I think it can be just left at 0 (or -1 if we go with option 1) .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the logic in line with your second suggestion 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe the
is_saas()
check belongs here. I'd rather allow our users to employ their Dynamo in the future, e.g., by writing a Dynamo cache backend.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I somewhat agree with this. Let me see if I can refactor this (and the environment variables as per the above conversation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking into this a bit more, I think my concern here is that this implies a much larger refactor.
I guess the ideal solution would be to refit our SaaS platform to essentially have something like:
where
cache.backends.custom.dynamodb
is our own implementation of the django cache backend which handles the interactions with dynamodb.While the prospect of this certainly excites me, I don't think it should necessarily be in scope for this piece of work.
An option to solve your direct comment here would be to remove the call to
is_saas()
and instead use some other setting, perhaps derived from whether e.g.ENVIRONMENTS_TABLE_NAME_DYNAMO
is set.Thoughts @khvn26?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually found a half decent halfway solution as there was already a conditional check in the code that was only relevant to the dynamodb path, so I've just used that as the check instead of
is_saas
for now. I still think the custom cache backend would be the best option, and may well simplify a lot of the dynamo integration code.