Means.Us.Com

Website DIY - tricks and solutions

Comet Cache and GeoIP: enable caching by page/visitor country instead of just page

Comet Cache (previously named Quick or Zen Cache) improves performance by serving a snapshot (cache) of a previously visited page, making it unnecessary for WordPress to generate a fresh “new” page for every visitor.

This causes the display of wrong content on sites that use country geo-location. This page should display your National flag . However, if the page was “first” requested by someone in Albania, Comet Cache would, instead, serve you the cached page with the Albanian flag. The Country Caching extension solves this problem.


In this article:

1. What the Country Caching Extension does
2. Installation and set-up
3. How do I know its working?
4. GeoLocation, and how to auto-update
5. Problems and Issues
6. Auto & Manual Uninstall
7. Warning


1. What the Country Caching Extension for Comet Cache does:

  • It builds an add-on script which uses an official Comet Cache interface to cache by page/country instead of just page. You can limit separate caching to specified countries.
  • It provides the GeoIP look-up to enable Comet Cache to determine the visitor’s country.


2. Installation and set-up of the Comet Cache Extension

Install in the normal way via “Dashboard->Plugins->Add New” and search for “Country Caching Extension“; or download from WordPress.Org.

Quick Setup:Dashboard->Country Caching“. Check the ” Enable CC Country Caching add-on” check box, and click save.

You can separately cache for ALL countries (Country Codes box empty).

Alternatively, you can allow most visitors to see the same “normal” cached page, and just specify specific countries that should have their own separate cache e.g. specify “FR,CA” if only visitors from France and Canada should see content different to the “normal” page. You can also define a group of countries that will share the same single cache.


3. How do I know it is working

Visit pages on your site using a couple of Browsers including Opera Developer which has a VPN allowing you to choose and pretend to be a visitor from different countries (note VPNs can be slow to load pages).

Check content is as expected for that country (if not you may need to clear existing Comet cache).

Comet Cache inserts hidden HTML comments at the bottom of pages and we can tell from these whether country caching is working.

<!-- Comet Cache file path: /cache/quick-cache/cache/http/example.com/somepage.v/US.html -->
<!-- Quick Cache file built for (US http/example.com/somepage/) in 0.43448 seconds, on: Dec 3rd, 2014 @ 7:21 pm UTC. -->
Snapshot for visitor located in the US.
NOTE: this WILL NOT BE DISPLAYED if you are using a plugin or CDN that is set to MINIFY HTML

  1. After installing Country Caching go to Comet Cache settings and clear the existing cache.
  2. Open a page on your site using a “virgin” browser (see below)
  3. View the source for the page e.g. if using IE right click on the page and select “view source” option
  4. Check the Comet Cache comments at the bottom of the source.

If Country Caching is working you will see the country code for your location is used as a suffix by Comet Cache (see “US” country code highlighted in yellow in the above example).

Testing GOTCHAs:

  • Comet Cache does NOT cache pages if you are (or have PREVIOUSLY been) logged in.
    To test, use a browser that has NEVER been used to log in to your site (if you can’t do this ensure you are not logged in and cookies are deleted before viewing a page).
  • If you are using a plugin or a CDN like Cloudflare with an option set to minify HTML then you won’t see these comments.

N.B. if you have limited separate caching to specific countries then ensure your country is in this list during your tests, otherwise you will (correctly) see Comet Cache comments indicating the normal cache is being used.

You can also test by using Opera VPN, or Country proxy servers.


4. GeoLocation, and how to auto-update:

If you use Cloudflare and have “switched on” their GeoLocation option ( see Cloudflare’s instructions ) then it will be used to identify visitor country. If not, then the Maxmind GeoLite Legacy Country Database, included with this plugin, will be used.

Updating The included Maxmind Country/IP range data files will lose accuracy over time. If you would like an automate update of these files then install the Category Country Aware plugin (here on WordPress.Org). Even if you don’t use any of its other features, it will automatically update GeoIP data “every 3 weeks”.


5. Problems and Issues

If the plugin is unable to save the generated add-on script it is probably due to your server’s permissions. Read Smashing Magazine’s article on WordPress Folder and File security requirements for different servers; and how to change WP Folder and File permissions.

If permission changes still do not enable the plugin to save the add-on script, then you can use the plugin’s option to download the add-on, which you can then manually upload to your server using FTP (see below).

Directory Permissions: Assuming you have a “typical” server, permissions for your WordPress “wp-content/” and “wp-content/ac-plugins/” (if it exists) folders should be set to 755 on a shared server, and 775 on a dedicated server; do NOT use slacker permissions.

File permissions for “cca_qc_geoip_plugin.php”: Old versions of the CC plugin (pre 0.6.2) were over zealous, and on first creating the add-on set permissions to 644. On a dedicated server this may prevent later changes to the add-on; to resolve this problem delete the add-on or change its permissions to 664. The current versions of the plug-in should correctly determine what file permissions to set.

Alternative solution: manual upload:

The “Files” tab with the download option (image above) will appear if the CC plugin is unable to create the add-on.

  1. Check that the country settings for the add-on are as required (these will be displayed just above the download button). If not, go back to the settings form “Comet/Zen/QC” tab, change the Country settings field and click “Save”.
  2. Click “download” to save the file (“cca_qc_geoip_plugin.php”) to your local machine.
  3. Use a text editor to open the file. It should contain PHP code; if just contains an error message then abandon the upload.
  4. connect to your server with FTP and change directory to the WordPress “wp-content” folder.
  5. if it doesn’t exist create the “ac-plugins” sub-directory under “wp-content” and go to it.
  6. upload “”cca_qc_geoip_plugin.php” to “ac-plugins”; then exit ftp.
  7. on the CC settings form switch to the “Zen/QC” tab, confirm you have completed the upload and click update.


6. Auto & Manual Uninstall

You should deactivate (removes the add-on script) and then delete the plugin in the normal manner. Then clear the Comet Cache cache (Dashboard->QuickCache->Clear)

However, just like with Comet Cache there may be occasions when the normal method fails to completely uninstall.

If all else fails:

  1. Log into your site via FTP; e.g. with CoreFTP or FileZilla.
  2. Delete this directory and contents: /wp-content/plugins/country-caching-zen/
  3. Delete this file: /wp-content/ac-plugins/cca_qc_geoip_plugin.php
  4. Then, via your WordPress Admin: Dashboard->QuickCache->Clear


7. Warning:

You should not use ANY Caching plugin OR extensions to them UNLESS you know how to use an FTP program (e.g. Filezilla). Caching plugins can cause “white screen” problems for some users; and sometimes the only solution is to manually delete files using FTP or OS command line. Comet/Quick/Zen cache is no different; when I checked the first page of its support forum it included 3 posts about this. The Country Caching plugin deletes files on deactivation/delete, but in “white screen” situations you may have to resort to “manual” deletion – see FAQ for instructions.

2 Comments

  1. Hi,

    I am using this plugin on one of my sites with zencache pro. The file permissions are alright and the addon file is in place. However, the plugin seems to be doing nothing. Separate caches are not served and there is no additional comment in zencache comments in page source.
    Any idea what the problem may be?

    • AW
      AW

      October 21, 2015 at 11:22 am

      Hi stingerpk,

      It’s working for me with the latest WP (4.3.1), Zen (150930), and CC extension (0.8.0). I’ve emailed you for more info.

Leave a Reply

Your comment will appear after its approved; usually within 12 hours but can be up to a week.
Your email address is optional and will not be published.

Copyright © 2015-2017  Means.Us.Com
This site recommends and is hosted by: Kualo Web Hosting.    
Theme: hemingway
 

Blog home  |  ↑ Top of Page ↑