Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm using Boost with Expire and it's working fine.
One thing I need to do in addition is use Rules to clear the cache for pages created by Views.
The "Clear URL(s) from page cache" works, but you need to enter each URL individually. This is fine, unless, say, your view uses pagination and/or arguments, and as well as clearing /viewpath you also need to clear /viewpath?page=1 and /viewpath/today etc.
Attached is a patch that allows you to pass a wildcard in Rules (or elsewhere) so that you can use
viewpath*
and everything matching that will get deleted.
Comment | File | Size | Author |
---|---|---|---|
#17 | boost_expire_wildcard support.patch | 2.99 KB | beauregard |
#14 | interdiff.txt | 2.22 KB | drclaw |
#14 | boost-expire_wildcard_support-1810936-14.patch | 3.56 KB | drclaw |
#7 | boost-expire_wildcard_support-1810936-7.patch | 2.99 KB | drclaw |
#6 | boost_wildcard.patch | 1.67 KB | jenshk |
Comments
Comment #1
apemantus CreditAttribution: apemantus commentedActually, this patch doesn't work, or rather it only works in a limited way.
At the moment, I'm dealing with the problem with using rules to execute custom PHP that uses _boost_rmdir and so removing everything in a directory. It's a pretty blunt tool but for now it works for my needs. If anybody can come up with a better way, although, I'm all ears...
Comment #2
apemantus CreditAttribution: apemantus commented[triple posting deleted]
Comment #3
apemantus CreditAttribution: apemantus commented[triple posting deleted]
Comment #4
bgm CreditAttribution: bgm commentedYour patchs makes sense, can you provide more info on why it didn't work?
I'm also wondering if this should not be an option in Expire to "clear other pages of Views with pagers", this way, other caches, such as Varnish, could also benefit from it. Not really sure on how to implement that though, since the view cannot really know how many pages there are (unless we run an expensive SQL query), so I guess we can resort to adding it to boost_expire in the mean time.
Comment #5
apemantus CreditAttribution: apemantus commentedThe issue for me (testing on Windows) was that glob("news*") matched "URLs — Boost files" like
news — news_.html
news?page=1 — news_page=1.html
But not paths like
news/tags/sport — news/tags/sport_.html
news/tags/business — news/tags/business_.html
i.e. it worked for pagination, not for arguments.
I ended up using a version of the patch to create a rule to delete pagination and then used _boost_rmdir to remove news/tags etc.
I think a version of this patch would probably be useful. I haven't tested it, but thinking about it now, I probably could have used the patch and done
news*
news/tags/*
news/authors/*
news/archives/*
This means that "wildcards" maybe work a bit different than you'd expect [if you had expectation that news* would match news/tags], but it would help with clearing views via expire + rules + boost.
I can't really think of a foolproof, universal way for expire to know about all possible views pages unless you had an optional module that hooked into views and logging the paths when they're created?
Comment #6
jenshk CreditAttribution: jenshk commentedI think this is what you are looking for.
Comment #7
drclaw CreditAttribution: drclaw commentedI might suggest an alternate approach.
hook_expire_cache()
now supports wildcards using it's own|wildcard
syntax. It would make more sense to support that since it's what people will likely be using.The attached patch expands
hook_expire_cache()
to respect the wildcard settings supplied by the expire module. We useglob()
for filename pattern matching to determine which files should be removed from the cache. Additionally, custom expire paths can include their own '*' wildcards which will be respected byglob()
.Not sure if this is the best approach, but I think it's at least a step in the right direction.
Comment #8
beauregard CreditAttribution: beauregard commentedI tested the patch from #7. Here my results.
Creating new node or editing a node: when saving:
Notice: Undefined variable: filename in boost_expire_cache() (Zeile 420 von /home/httpd/vhosts/lcdfernseher.ch/subdomains/exchtest/httpdocs/sites/all/modules/boost/boost.module).
These error appears up to 15 times on the page
Wildcard-Tests
1. mylist|wildcard
mylist is a paged view.
It worked and deleted all cached view pages
2. pagewithview|wildcard
pagewithview is a page with an embedded view. This view is paged.
It worked and deleted all cached view pages
3. cars/|wildcard
cars is a directory and I wanted to delete all nodes which are in www.mydomain.com/cars/.
This had no effect. Is it not possible or must I pass it with another syntax?
4. cars/adm|wildcard
Should delete all caches of nodes starting with “adm” in www.mydomain.com/cars
This had no effect. Is it not possible or must I pass it with another syntax?
Comment #9
shortspoken CreditAttribution: shortspoken commentedHi. I also tested this and confirm that its working with the following pattern:
node_alias?date=*
Although I am getting this watchdog error message too:
Notice: Undefined variable: filename in boost_expire_cache() Line 420
Comment #10
beauregard CreditAttribution: beauregard commented@shortspoken
"node_alias" is the clean-url of your node?
how exactly was your pattern working? I thought that * does not work with boost.
@drclaw/maintainers
Is there any plan to fix this code, so we could use it productively? Can I sponsor it?
Comment #11
shortspoken CreditAttribution: shortspoken commentedSorry for not being clear enough. I wanted to expire also the paging and date-urls of my nodes as I use the views (date) pager.
Not only "cleanurl" should be cleared but also "cleanurl?page=1" and all other pages.
So I added the lines to the custom pages of the expire cache settings of my content type:
cleanurl?date=*
cleanurl?page=*
Note that the * has always to be at the end.
Comment #12
beauregard CreditAttribution: beauregard commentedOk, now I understood when I tested. I assumed that * should not be used. But I am confused why now |wildcard and * can be used, however differently.
Example of a paged view
mylist|wildcard
--> Correctly deletes all pages of the view
mylist*
--> Does not delete all pages of the view
mylist?page=*
---> Deletes all pages of the view, except the first page (logical, because the first page is /mylist
My points 3&4 above work with *.
@drclaw
It would be very helpful if you could shortly outline how this is now implemented with both types of wildcards. Is there a reason to use both?
Comment #13
drclaw CreditAttribution: drclaw commentedHello All,
Thanks for testing out the patch and providing such detailed feedback! I've tested out the different scenarios you've all described and adjusted the logic in the patch.
Here's how the patch now works after the adjustment:
cars
, we'll only check for that one page's cache entry and delete it if it exists (technically we'll look for the file named "cars_.html").cars|wildcard
we'll flushcars_.html
,cars-audi-a4_.html
,cars/
,cars_preowned/
etc.). Technically what we're doing is concatenating a "*" to the path and running it throughglob()
and removing any file or directory matches.@beauregard: To clarify about the two types of wildcards, I was just pointing out that since we're using the php
glob()
function, you could technically use any of the pattern matching characters it supports ("*" and "?"). However, this new patch is slightly different than the old one. Now, we only useglob()
if a wildcard has been specified using the expire module "|wildcard" syntax. Paths likemylist?page=*
won't work with this new patch. The only real use case for using a glob wildcard would be for some kind of advanced pattern matching. For instance you could provide a path likecars/audi*2014|wildcard
to match paths likebut not
Hope this makes sense to everyone. Ask away if there are any questions (I'll try to respond quicker this time!)
drclaw
Comment #14
drclaw CreditAttribution: drclaw commentedSorry, small error in last patch :O
Use this one.
Comment #15
beauregard CreditAttribution: beauregard commentedHi
Thanks for the update and explanations. I just installed and tested it. I still get a list of warnings when I update a node: Notice: Undefined variable: filename in boost_expire_cache() (Zeile 419 ..../sites/all/modules/boost/boost.module).
You don't have these warnings?
Comment #16
drclaw CreditAttribution: drclaw commentedI don't get that warning... but let me try on a fresh install and get back to you.
drclaw
Comment #17
beauregard CreditAttribution: beauregard commentedHi
I asked a freelancer doing work for me to check this. He made a small change and now it works on my server without warnings. Please see the enclosed patch.
@shortspoken: Could you test it on your server too, because you get the warnings as I did?
best regards
Comment #18
garamani CreditAttribution: garamani commentedThanks beauregard, The Patch #17 Works fine but for the latest version 7.x-1.0 there is a redundant closing curly bracket:
The last part of patch should looks like this:
Edit: The Patch (#17) works without the modification above!!
Comment #19
beauregard CreditAttribution: beauregard commentedHi
I applied the patch from comment #17 to the latest version 7.x-1.0 and I have it running on 3 productive sites since 3 weeks. It works without any problem.
I asked now the freelancer who works for me and he said that you added a new else statement:
But this won't work, because filename is not known at this place of code.
So, the question is what happened: Did you apply my patch to the latest version and it did not work? Are we not using the same versions? Why you added this else statement?
best regards
Comment #20
Anonymous (not verified) CreditAttribution: Anonymous commented@beauregard - it would probably help if you we specific in who you are questioning.
There is a stable version of boost and a development version, this is marked as being for the development thread (by someone), it is probable that someone's been looking at the different versions.
Comment #21
garamani CreditAttribution: garamani commented@beauregard
You're right, that was my mistake. The patch #17 works perfect and No modification needed.
Comment #22
rroblik CreditAttribution: rroblik commentedWorking fine !
Maybe put this patch in a new
dev
release ?Thanks
Comment #24
bgm CreditAttribution: bgm commentedApplied to 7.x-1.x using #14 then a diff of #17 (in an attempt to commit with proper credit). Thanks for the patches and testing!
Can anyone do a last review before releasing the next version of Boost? I spent a bit too much time understanding the two patches, and probably not enough testing.
Comment #25
rroblik CreditAttribution: rroblik commentedWorking fine for me :)
Comment #27
azinck CreditAttribution: azinck at Forum One commentedThis fix isn't quite right. The patch in #14 was much better than what got committed, I believe. See here: #2710449: Wildcard matching for expiration doesn't descend into subdirectories