• Hi Donncha,

    i want to display a welcome box for first time visitors. This box is only generated if a specified cookie doesn’t exist. To work smoothly with wp supercache i wrote a supercache-plugin.

    As far as i understood one has only to change the cache_key so another file is generated for this cache ( wp-cache-md5($cache_key).html ). My method looks like:

    function wp_add_first_time_visit_cachekey($key) {	
    
    	if(!isset($_COOKIE['visited'])) {
    		$key .= 'firsttime';
    	}
    
    	return $key;
    }
    
    add_cacheaction( 'wp_cache_key', 'wp_add_first_time_visit_cachekey' );

    Everything worked fine on my previous installation. But i just changed my theme and therefore also updated WP to 3.1.2. (i know, never change a running system -.-). I also deleted some plugins and added new ones. Domain mapper is now installed ( thanks 😉 ).

    Ok i think the problem is, that there are mostly supercache/sitename/path-to-post/index.html files generated instead of wp-cache-md5 ones. It’s my guess that it has something to do with the domain-mapping plugin. How can i fix this issue? I just want to serve different caches based on a cookie value.

    I am using Wp-Supercache 0.9.9.9. Mode is set to PHP and my htaccess is cleaned.

    Btw. Thanks for the great work you did with the wp-supercache plugin!

    -Alex

Viewing 8 replies - 1 through 8 (of 8 total)
  • Are you sure that plugin is still activated? Try legacy mode instead?

    I would implement this in Javascript rather than PHP. Then you can server supercached pages to every user. The Javascript would detect if the cookie was there, and set it and display the message if not.

    Thread Starter harlekinx

    (@harlekinx)

    Yes i’m sure it’s active (log-file is generated).

    Javascript would work only for those who have js enabled (10% doesn’t according to analytics) and i can’t get the http_referer. The code above is only a snippet of my script. I also make different boxes for different referers. Another plugin of mine (doesn’t work anymore) handles the location-setting. I show different posts in the stream for different locations (Austria – Germany). So JS isn’t really a solution.

    Do you have another guess why it doesn’t work anymore. Or can i stop the process of making supercached pages and only serve the wp-cache-md5 files? Is this a good idea? Why are wp-cache- files and supercached files generated anyway?

    Thanks
    -Alex

    Thread Starter harlekinx

    (@harlekinx)

    hi, i’m still stuck on this one. Do you have any further suggestions?
    Please help.

    I don’t see why you can’t use AJAX to load a PHP script that does all the heavy lifting and print the message to the user. Sure, 10% might not have JS installed but they’re not going to be your average user anyway.

    Thread Starter harlekinx

    (@harlekinx)

    Hi Donncha,

    sure it is a solution for the fancybox-problem, but not for the location-problem. Can you have a short look on my site.

    In the upper right corner is a dropdown containing flags. If you switch to the austrian flag, you only see content which is appropriate for austrians. This works because of the GET Parameter (supercache doesn’t cache requests with GET parameter). Now the cookie pj_lang is set and on the next request it should load a cache file with the Countryname in the cachekey, but this doesn’t work.

    Now i may have found a solution for my problem but i’m afraid to change this setting without your insights.

    A excerpt of my current wp-cache-config.php:

    $cache_compression = 0; //Added by WP-Cache Manager
    $cache_enabled = false; //Added by WP-Cache Manager
    $super_cache_enabled = true; //Added by WP-Cache Manager
    $cache_max_time = 3600; //in seconds
    //$use_flock = true; // Set it true or false if you know what to use
    $cache_path = WP_CONTENT_DIR . '/cache/';
    $file_prefix = 'wp-cache-';
    $ossdlcdn = 1; //Added by WP-Cache Manager

    As i stated befor i think the problem is caused by the supercache files. And everything worked fine on a old version of wp-supercache, where only wp-cache file were generated (i’m not one-hundret percent sure about this 😉 ).

    Is it save to change the settings to

    $cache_enabled = true; //Added by WP-Cache Manager
    $super_cache_enabled = false; //Added by WP-Cache Manager

    What do you think?

    Go grab the development version and test it ON A DEV SERVER, not production. It has code that changes the supercache files so they can be served to non anonymous visitors.

    Look at the mobile detection code in wp-cache-phase1.php for code that makes it work. You should be able to use Supercache files with this.

    Thread Starter harlekinx

    (@harlekinx)

    hi donncha,

    i made the previous changes to the config file and everything works fine now.

    For the record: it seems to me, that supercache plugins which edit the cachekey via wp_cache_key only work if you set super_cache_enabled to false. Caching still works as cache_enabled is activated. So i don’t know if there are any drawbacks?

    I figured out that supercache plugins are executed even if no cache was generated (because it was a known user). Is this a desired behavior?

    Is your Amazon wishlist up to date? – http://www.amazon.co.uk/gp/registry/35ZCGIU2AH4NB

    You’ve disabled supercaching by setting super_cache_enabled to false. I presume you’re getting lots of wp_cache* files in wp-content/cache/ ?

    The only real drawback is that the plugin slows down if you have lots of wp_cache cache files. Keep the timeout low and experiment by changing it and keeping an eye on load. If you have lots of those cache files it can take longer for the plugin to update cache files as it needs to open each one to figure out what it’s caching.

    Yup, wishlist is up to date now 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to: Serve different cache based on cookies etc.’ is closed to new replies.