Hello,
I'm sure this question has been answered but I haven't found an answer through Google yet.
I have performances > caching disabled on my website, and so I have set up most of my views to be cached directly from views (1 hour / 1 hour) to get better performance. My question is, is the cache cleared if I run manually : http://mydomain.com/cron.php?
I have tested it to see but nothing seems to be happening, it still seems to be showing the old content in a views block after I run cron.php
Thanks,
Comments
Comment #1
dawehnerNo it does not clean the cache with cron.php
If a user comes on your site 1.05h after the cache was created, the cache item will be removed, the query will be run, the output, too and the cache item will be saved.
Comment #2
gafir777 commentedHi dereine,
Thanks for your answer. From time to time, I will need some other contributors (not admin) to the website to be able to clear the Views cache so that some of the views blocks are updated with the latest node for instance.
I noticed the Views cache can be cleared manually from /admin/build/views/tools. There's a Clear Views' Cache button. However, I'm wondering if there would be a way to just give them a URL similar to /cron.php that would clear the Views' cache so that everything gets updated if needed. If a URL isn't the easiest way, maybe I could use a trigger: "On node creation" >> action: " Clear Views' cache". Not sure how to do this though.
Thanks,
Comment #3
gafir777 commentedJust found the cache_clear_all(); function. I'm wondering if this would work as part of a page to load for contributors to clear the views' cache after they have posted a new node.
Something like: After they save a node, load: www.domain.com/clear-my-cache -- a page with that function embedded with input php. I'm using syndicated css and js though, and I do not need these to be re-syndicated every time we want to clear the views' cache though.
Comment #4
gafir777 commentedDescribing my steps as I'm trying to figure it out:
here is the api page for the cache_clear_all() function: http://api.drupal.org/api/function/cache_clear_all/6
It doesn't seem like the function is clearing the cache views tables by default, because if the arguments are not specified, it will clear:
Now, I believe I could do:
or something similar, but I'm not sure which tables should be cleared.
Comment #5
merlinofchaos commentedUse views_invalidate_cache() or the button that's on administer >> views >> tools
Comment #6
gafir777 commentedThanks for your help, Merlin.
Comment #7
gafir777 commentedOk, sorry to be persistent with this, but I created a php file in the root of my website with this:
I have some views cached with random: global to check if the cache is cleared or not.
When I click on the /administer/views/tools >> clear Views' cache button, my views block changes its display, so the cache is cleared.
However, when I load http://www.domain.com/clear-my-views.php -- I'm getting a blank screen just like cron.php, but the views remains the same, which means the cache isn't cleared I believe.
I also tried to insert
in an unpublished node and with input php again without success, the cache isn't cleared.
Thanks for your help,
Comment #8
merlinofchaos commentedOh hm. views_invalidate_cache actually probably won't clear cached data.
use cache_clear_all() on the 'cache_views_data' table.
Comment #9
gafir777 commentedIt worked! Thanks Merlin!
Comment #10
gafir777 commentedJust a question, if two people were to access the page where I have cache_clear_all('*', 'cache_views_data', true); at the same time, could it create problems with the database?
Comment #11
merlinofchaos commentedOnly possibly causing it to cache multiple times. Should be fine.
Comment #13
peterpoe commentedSorry if I make you repeat, but I need a confirmation as this is on a production site.
I have set up a Rule that runs the following php code every time new content is created:
Is this correct?
Note: I found that often my views would exceed the maximum cache lifetime and continue showing stale data. What could cause this?
Comment #14
dawehnerI don't get why you have to clear both caches, but anyway this looks fine.
There is a issue for this. Please search the issue queue for it, thanks.
Comment #15
iamjon commentedMarking this as fixed