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 ability to ask external caches to invalidate. #7893

Merged
merged 1 commit into from
Sep 15, 2023
Merged

Conversation

dracos
Copy link
Member

@dracos dracos commented Sep 8, 2023

Add a cached_urls method to the Comment, FoiAttachment, InfoRequest, PublicBody and User models, containing the entries that those models wish to invalidate when an event is logged via log_event or when the censor rules change. Entries are either a fixed path to be purged or a regex beginning with '^' to be banned.

Adds a NotifyCacheJob that for each of the object's cached_urls, for each locale, for each host in VARNISH_HOSTS, makes BAN or PURGE HTTP requests to the host, to invalidate the relevant entries.

@dracos dracos force-pushed the banned-on-the-run branch 3 times, most recently from 032a22d to d4923b4 Compare September 8, 2023 09:29
@garethrees
Copy link
Member

I expect you're aware but if not FYI Alaveteli has some prior art of this: #4252, #4232

@dracos
Copy link
Member Author

dracos commented Sep 8, 2023

Hi @garethrees, yes, thanks, I've put all the detailed discussion on https://github.com/mysociety/sysadmin/issues/1824

@dracos dracos force-pushed the banned-on-the-run branch 7 times, most recently from 567c622 to 7bda1a8 Compare September 8, 2023 19:02
@dracos dracos changed the title [wip] cache banning Add ability to ask external caches to invalidate. Sep 8, 2023
@dracos dracos force-pushed the banned-on-the-run branch 7 times, most recently from a50895d to 38b15b5 Compare September 11, 2023 08:13
@gbp gbp self-assigned this Sep 11, 2023
Copy link
Member

@gbp gbp left a comment

Choose a reason for hiding this comment

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

This is looking good to me. There are more I could do to this but for now I have committed some fixups to do things is slightly better Ruby approach but functionally this should be the same. Many thanks @dracos

Changes:

  1. remove multiple conditionals, in favour for a callback when enqueuing the job
  2. move post event logging code into InfoRequestEvent after create callback, and added specs
  3. refactored job, removing heavily nested code and improve success/failure logging.

@dracos
Copy link
Member Author

dracos commented Sep 14, 2023

Thanks - that callback is definitely nicer :) Only query I have is can Net::HTTP hold open a connection - I had it outside the URLs loop in the hope it would use the one connection for all of them, but probably makes no difference.

@gbp
Copy link
Member

gbp commented Sep 14, 2023

Only query I have is can Net::HTTP hold open a connection

Ah, as it is then no it doesn't. We can close the connection manually though if we don't use a do/end block. I'll push another fixup.

Add a cached_urls method to the Comment, FoiAttachment, InfoRequest,
PublicBody and User models, containing the entries that those models
wish to invalidate either when an event is logged, via log_event, or
when the censor rules change, or when a body or user is updated. The
entries are fixed paths to be purged, or regexes beginning with ^ to
be banned.

Adds a NotifyCacheJob that for each of the object's cached_urls, for
each locale, for each host in VARNISH_HOSTS, makes BAN or PURGE HTTP
requests to the host, to invalidate the relevant entries.
@gbp gbp merged commit fa0ea12 into develop Sep 15, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants