caching member requests based ONLY on alternate cookies?
-
Hi, what is best practice for caching files based only on specific cookies? (and ignoring the login cookies)
Background: a membership site where most visits are by members, and members of the same role all receive the same content for a request to a given post.
i.e. ignoring wordpress_, wordpress_sec_ and wordpress_logged_in_ cookies.
I used:
do_action( 'wpsc_add_cookie', 'swpm_in_use' ); do_action( 'wpsc_add_cookie', 'swpm_role' ); do_action( 'wpsc_delete_cookie', 'wordpress_logged_in_'.COOKIEHASH ); do_action( 'wpsc_delete_cookie', 'wordpress_sec_'.COOKIEHASH ); do_action( 'wpsc_delete_cookie', 'wordpress_'.COOKIEHASH );
I thought this should register the two cookies we want to cache on (they’re set elsewhere and only valid while logged in), and remove the wordpress auth cookies from the cookies used for the cache key, but it only adds the two cookies to cache config and ignores the deletes, so caching is now based on the wordpress auth keys AND those two cookies.
It seems to be working by adding:
add_cacheaction( 'wp_cache_get_cookies_values', 'swpm_get_rolebased_cachekey' ) swpm_get_rolebased_cachekey($key){ $key=''; //then does some work to set a key based on cookies we care about return $key; }
This seems to get it caching how we want it, based on logged in user’s roles, rather than logins. (Profile related pages are set as excluded from cache)
Is this the proper way? It feels ‘wrong’ being able to explicitly say “don’t use this cookie” but still have it checked, I don’t know if I missed a clear way to say “only use cookie X,Y,Z”.
Also, to prevent a specific role/users requests being cached at all, is the proper way to determine if they are user/role X then something like?
if ($my_requests_should_not_be_cached){ global $cache_enabled; $cache_enabled = false; if (!defined('DONOTCACHEPAGE')){define( 'DONOTCACHEPAGE', 1 );} }
(apologies, new to wordpress and php in general. Thanks for any help)
- The topic ‘caching member requests based ONLY on alternate cookies?’ is closed to new replies.