Home > views > How to setup Page Cache to work with the Flag Module and Views?

How to setup Page Cache to work with the Flag Module and Views?

June 18Hits:1
Advertisement

I have a Site where Views are used to display flagged Nodes. When i turn on Cache Pages for anonymous Users, the anonymous Users only see the change in the Views until the cache is cleared. (If logged in no problem). What is the best Way to deal with this caching issue. I would prefer that all pages with views where item flags are updated would be recached. Is this possible ?

Answers

Similar to the first answer but not assuming your cache is in the database. (memcache, redis, apc, etc)

function hook_flag_flag($flag, $entity_id, $account, $flagging) {
  $view_name = '<view_name>';
  $display_id = '<display_id>';
  $cid = $view_name . ':' . $display_id . ':*';
  cache_clear_all($cid, $bin = 'cache_views_data', $wildcard = TRUE);
}

You can achieve this functionality using the Flag module hook_flag_flag, This hook will act on an object being flagged.

In this hook you need to clear the cache data for that particular view from cache_views_data table.

Below is the sample code,

function hook_flag_flag($flag, $entity_id, $account, $flagging) {
  $view_name = '<view_name>';
  $display_id = '<display_id>';
  $cid = $view_name . ':' . $display_id;
  if (db_table_exists('cache_views_data')) {
    db_delete('cache_views_data')
      ->condition('cid', db_like($cid) . '%', 'LIKE')
      ->execute();
  }
}

Usually views will set the cache ID based on the view name, display id and other data being passed.

Below is code snippet which prepares the cache ID for views result

$this->_results_key = $this->view->name . ':' . $this->display->id . ':results:' . md5(serialize($key_data));

So specify the cache ID accordingly in the delete query. However make sure to not to delete other entries in the cache_views_data table.

Hope this helps.

Related Articles

  • How to setup Page Cache to work with the Flag Module and Views?June 18

    I have a Site where Views are used to display flagged Nodes. When i turn on Cache Pages for anonymous Users, the anonymous Users only see the change in the Views until the cache is cleared. (If logged in no problem). What is the best Way to deal with

  • Page Caching wrong CSSJune 9

    got a weird issue I was hoping someone could help with. I have a site that uses multiple subthemes, with different ones being served depending on url var. IE, subsiteone.mysite.com, and subsitetwo.mysite.com get different themes, but the same content

  • Page caching with multiple versions of the cacheOctober 13

    My site is very much faster with page caching on. However, I have a custom module that serves 5 different slightly different versions of my content. In other words, people in New York see East Coast stories, but not California stories, but everyone s

  • Passenger, Apache and avoiding page cachingMarch 22

    I'm hosting a rack application with passenger and apache. The application is setup to cache the content of each request to the public directory after each request. This allows apache to serve the content directly as a static page for future requests.

  • Is it possible to update Drupal page cache right after it is cleared?February 20

    I am trying to improve Drupal performance and I have all the tuning usual suspects setup: Varnish Memcache APC Drupal core cache From what I understand when you clear the Drupal cache it does not replenish page caches until an anonymous end user make

  • Config setting for disabling page cacheApril 4

    Is there a config setting for disabling page cache in EE? I've found a setting for disabling tag caching $config['disable_tag_caching'] but not one for pages. I'm using the Focus Lab master config setup and would like to easily turn off page caching

  • APC object caching in combination Batcache/memcached page caching?June 30

    In the post WordPress Caching Comparisons Part 2 Matt Martz compares different caching setups, among them APC object caching together with Batcache page caching. In his post this combination seems to be the best tradeoff between setup complexity and

  • Linux page cache slows down IO on dual cpu server with 64GB ram

    Linux page cache slows down IO on dual cpu server with 64GB ramMay 16

    I have a massive problem with the linux page cache which slows down the IO. For instance if I copy a lvm partition with dd, linux cache the data in the buffers or caches (free –m). That is not the problem, but after the buffer reaches a special value

  • What should my Nginx rewrite rules be for Rails with Passenger for page caching in a subdirectory?January 24

    I'm using Nginx 0.7.64, Passenger 2.2.9, Rails 2.3.5. I have my page caching directory set to /public/cache, and I'd like to be able to serve cached pages when requested over HTTP, but always hit the Rails app when requested over HTTPS. The bulk of m

  • Where does Plesk pull its list of available shells under the domain setup page? February 5

    Does anyone know where Plesk pulls its list of available shells under the domain setup page? I am on a box which is missing /bin/bash (chroot), though the majority of the system users on the machine have the shell: /usr/local/psa/bin/chrootsh On a re

  • Passenger: mod_rewrite rules for non-default page cache directory for Rails applicationFebruary 16

    Does anybody have some working Apache mod_rewrite rules that enable Phusion Passenger (mod_rails) to use a non-default location for the page cache within a Rails application? I'd like the cached files to go in /public/cache rather than the default of

  • Westell router setup pageMarch 25

    I can connect to the internet, ping 192.168.1.1 with no problem, haven't changed any firewall or Anti-virus settings, but bringing up 192.168.1.1 in the browser gives 'Problem loading page'. XP machine...was able to connect to the setup page few week

  • How to set default "Page Setup →Page Size" as A4 in Firefox?September 3

    In my Firefox (linux) I can change the page as A4 in File → Page Setup → Page Size. Doing this, I inform the browser to print my pages as A4, instead of the default of Letter. My printer doesn't have Letter paper size (it just exists in USA). If it f

  • Solaris 10: What does "Page cache" stand for in "echo ::memstat | mdb -k"May 17

    When running "echo ::memstat | mdb -k" I get this result: Page Summary Pages MB %Tot ------------ ---------------- ---------------- ---- Kernel 2349789 9178 14% ZFS File Data 4251652 16608 25% Anon 8101424 31646 48% Exec and libs 51583 201 0% Pa

  • SQL 2005 - Disable Page CachingJune 22

    I know this is kind of a funny request, but I'd like to disable page caching on our development database. I believe it would make it much easier to see the impact of various tweaks that are done, and I'm most curious about time to retrieve uncached p

  • Page cache for categories not updating with W3 Total Cache August 9

    I noticed recently that the full page cache for category pages isn't getting updated. Other pages seem to work fine (home, posts, etc) but categories cache files stay untouched for days until I manually rm -rf them. What could cause this? Plugin upda

  • Magento Full Page Cache & Load TestingAugust 15

    Magento Enterprise 9 Full Page Caching is on Cache depth: 1 (ex. catalog.html?p=1) Current results from JMeter after about 1,000 samples: Throughput: Homepage: 8.5/sec - ~40kb Catalog: 6.1/sec - ~65kb Error rate is very low, 0% for homepage, and 1.1%

  • OpenVZ with RHEL6 kernel & page cache?September 15

    After upgrading kernel from debian 2.6.32-openvz-amd64 to RHEL6 2.6.32-042stab035.1, I have problem with kernel page cache. Looks like no OpenVZ containers use page cache and now I have 10-15GB free RAM and only 3-5GB cache generated by mysql server

  • mod_rewrite rules for non-default page cache directory for Rails application with distinction between mobile directory and www directoryNovember 16

    My Question is similar (almost the same) to another question asked here: but with a twist. Does anybody have some working Apache mod_rewrite rules that enable Phusion Passenger (mod_rails) to use a non-default location for the page cache within a Rai

  • Headway body classes and W3TC page cache conflict January 9

    I'm currently working on a website using WordPress, Headway, Modernizr and W3 Total Cache. The problem I'm having is that W3TC is caching the body tag, which means that this isn't being updated depending on the users browser by Modernizr. An example

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 1.075 s.