1

Just started a gigantic Drupal build and I'm trying to validate if the Context Module is the correct option for a segmented content delivery system. It appears to be and I am optimistic.

The project calls for about 100 custom "variables" that the site administrators can segment content with. As a test, I've created a custom context condition of time of day. If the condition is set for >= 2PM for example with a reaction of showing the Powered By Drupal block in the footer, everything works as expected - Before 2PM, no block and after 2PM, block. So the context condition is working as expected.

Now, I've enabled page caching with lifetime and expiration set to 1 day. If I clear the cache before 2PM and hit the page, the block does not show as expected. If I hit the page (which is previously cached) after 2PM, still no block.

I have used a "preboot" method to modify the cache key, but in my example above, the cache key would include the hour and the minute, effectively reducing the cached copy of a page to 1 minute. I might as well turn page caching off in that case!

Is it possible to run the context conditions on a cached page? Has anyone found a way to make this happen?

  • I've enabled page caching with lifetime and expiration set to 1 day. If I clear the cache before 2PM and hit the page, the block does not show as expected. If I hit the page (which is previously cached) after 2PM, still no block. Do you know at what time is your cache clearing? I believe it's 24hrs from clicking the save button, when you set cache to 1 day. So if you click it at 11pm, it won't be clearing till then. – No Sssweat Mar 17 '16 at 19:46
  • The more I look at this problem the more inclined I am to turn off page caching and rely on block caching only. – Scott Joudry Mar 17 '16 at 23:48
0

If you have access to your ssh console, you can use cron

crontab -e

Then you put inside, at the bottom:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
0 14 * * * cd /var/www/drupal && drush cc all

the above will clear the cache with drush everyday at 2pm.

A few notes:

  • replace cd /var/www/drupal with the actual path to your drupal.
  • I believe the default runs at UTC time.
  • You need to install drush if you haven't already.

An alternative to using Drush, you could create a PHP or Python or NodeJS etc.. file that uses mysql to delete the row that holds the page cache in your DB, and run the file with cron at 2pm.

  • My issue is not with clearing the cache, but allowing context rules to run on cached pages. The example context rule above is time of day, but it could just as well be device (tablet, mobile, desktop). – Scott Joudry Mar 18 '16 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.