GitXplorerGitXplorer
i

Yourls-APC-Cache

public
28 stars
5 forks
6 issues

Commits

List of commits on branch master.
Unverified
628bea5d616f5c6147cd795a97089ee5062bf72f

Allow skipping click tracking with APC_CACHE_SKIP_CLICKTRACK in order to use with the SDB logging

iianbarber committed 13 years ago
Unverified
3391a09a9b3bb09ac2b29cd9d882b039af7d9e70

Clear cache when a link is edited

iianbarber committed 14 years ago
Unverified
5bcfe64294769733fec1378ed891ebe2e06c9cac

Use plugin directory define for loading

iianbarber committed 14 years ago
Unverified
f76384e04da566fda62c5e7d5115de570a0620ec

Adding a hook to clear cache on plugin activation

iianbarber committed 14 years ago
Unverified
c337ec6ac70ebf49cb5d14981978fef06e4c2e17

Updating to work with hooks in latest YouRLS trunk

iianbarber committed 14 years ago
Unverified
16bced2e528968fdc6042da42c9c3e03b63ee229

Some tweaks based on feedback from Ozh

iianbarber committed 14 years ago

README

The README file for this repository.

A caching plugin for the Yourls (http://yourls.org/) URL shortener.

Note: Looking for a more recently updated Yourls cache plugin with more features? Try https://github.com/tipichris/YAPCache - Chris Hastie's excellent new plugin (which includes some useful bugfixes!)

To use, just take the apc-cache/plugin.php file and put in user/plugins/apc-cache, and put the cache.php file in user/. A recent version of APC is required.

This plugin is designed to remove a lot of the database traffic from YouRLS, primarily the write load from doing the logging and click tracking. We have attempted to strike a balance between keeping most information, but spilling it in some cases in the name of higher performance.

Configuration - Define the following in your config.php to control the plugin: define("APC_READ_CACHE_TIMEOUT", 360);

  • Integer number of seconds that data from the DB will be cached define("APC_WRITE_CACHE_TIMEOUT", 120);
  • Integer number of seconds of time to buffer incoming writes (minimum) define("APC_CACHE_STATS_SHUNT", "none");
  • This will cause the caching of the clicks and logredirects to be disabled, and the queries logged as normal. This is handy if you want to keep the URL caching, but still have 100% accurate stats (though the benefit of the plugin will be pretty small then). define("APC_CACHE_STATS_SHUNT", "drop");
  • This will cause the clicks and log redirect information to be dropped completely (a more aggressive NOSTATS) - so there will be no clicks or logredirects logged. define("APC_CACHE_SKIP_CLICKTRACK", true);
  • This will cause the plugin to take no action on click/redirect logging (if this is being handled by another plugin for example).

There are roughly four processes in the plugin:

Keyword Cache: We cache the keyword -> long URL look up in APC - this is done on request, and cached for about 2 minutes (this can be changed by tweaking the define)

Options Cache: Just caches the get all options query

Click caching: Rather than writing to the database, we will write first to APC. We also create another cache item, with an expiry of 2 minutes (unless changed). When we can create that timer (so there never was one, or a previous one had expired) we will write the click to the database along with any other clicks that have been tracked in the cache. Practically this means the first request hits the DB, then it will at maximum before one DB write per 2 minutes for click tracking. The downside is that you are almost guaranteed to miss some clicks - if the last person to click does trigger a DB write, their click will likely never be tracked. This was more than acceptable to us.

Log caching: Similar to the click tracking, but in this case we consider all log writes as separate events in the same buffer. We use an incrementing counter to track our unwritten logs, and after a 2 minute expiry using the same mechanism as before we will flush the cached log entries to the database. Log entries can still be lost, and of course APC may clear items to free cache space at any time, or on webserver restart.

This plugin is really only for a narrow range of cases - if you want full speed it's probably best to just disable logging any of the log/click information at all, so there are no writes because of it. If you want full information, it's best to log each click. That said, please report any issues in the Github issue tracker.