{"id":38534634,"url":"https://github.com/ndejong/CakephpAutocachePlugin","last_synced_at":"2026-01-25T02:01:14.921Z","repository":{"id":2066637,"uuid":"3005298","full_name":"ndejong/CakephpAutocachePlugin","owner":"ndejong","description":"CakephpAutocachePlugin is a CakePHP 2.x Plugin that makes query caching as easy as adding a 'autocache'=\u003etrue condition to your Model query","archived":false,"fork":false,"pushed_at":"2018-07-15T14:17:24.000Z","size":31,"stargazers_count":33,"open_issues_count":0,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-18T06:42:38.732Z","etag":null,"topics":["cakephp-plugin","cakephp2","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Tivix/django-rest-auth","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ndejong.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-12-18T09:28:27.000Z","updated_at":"2022-03-28T07:17:47.000Z","dependencies_parsed_at":"2022-08-23T13:50:34.742Z","dependency_job_id":null,"html_url":"https://github.com/ndejong/CakephpAutocachePlugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ndejong/CakephpAutocachePlugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndejong%2FCakephpAutocachePlugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndejong%2FCakephpAutocachePlugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndejong%2FCakephpAutocachePlugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndejong%2FCakephpAutocachePlugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndejong","download_url":"https://codeload.github.com/ndejong/CakephpAutocachePlugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndejong%2FCakephpAutocachePlugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28741625,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T01:40:51.112Z","status":"online","status_checked_at":"2026-01-25T02:00:06.841Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cakephp-plugin","cakephp2","php"],"created_at":"2026-01-17T07:00:28.917Z","updated_at":"2026-01-25T02:01:14.911Z","avatar_url":"https://github.com/ndejong.png","language":"PHP","readme":"CakephpAutocachePlugin\n======================\n\nCakephpAutocachePlugin is a CakePHP 2.2+ Plugin that makes query caching as easy \nas adding a 'autocache'=\u003etrue parameter to your Model query.  This plugin follows \non from CakephpAutocacheBehavior on Mark Scherer's (https://github.com/dereuromark) \nsuggestions, thanks Mark!\n\nThe CakephpAutocachePlugin PHPUnit tests have been confirmed against:-\n - cakephp-2.6.0-RC1\n - cakephp-2.5.7\n - cakephp-2.4.10\n - cakephp-2.3.10\n - cakephp-2.2.9\n\nNB: CakephpAutocachePlugin uses Cache grouping functionality which only became \navailable in CakePHP version 2.2 - Groups are defined on a per Model basis hence\nchanges to a Model will invalidate all other cached data for the same Model\n\nDownload\n--------\n - https://github.com/verbnetworks/CakephpAutocachePlugin\n \nNB: this repo has been moved (2018-07) from its original location at:-\n - https://github.com/ndejong/CakephpAutocachePlugin\n\nInstall\n-------\n\n### Step 1 - via github.com\nCopy or symlink CakephpAutocachePlugin into a path named Autocache in your Plugin\npath like this:-\n\n    app/Plugin/Autocache\n\nTake careful note of the pathname, the name is \"Autocache\", not AutocachePlugin\nor CakephpAutocachePlugin, it's just Autocache.  I spell this out because it's\nan easy thing to trip up on especially if your pulling this down from github or\nunpacking from a tarball.\n\n### Step 1 - via composer\nAdd the following to the require section of your composer.json:-\n    \"verbnetworks/cakephp-autocache-plugin\": \"dev-master\"\n\n### Step 2\nMake sure you have at least one standard CakePHP cache configuration setup in \ncore.php or bootstrap.php.  You can call your first cache configuration 'default' \nand just set it up as a File based cache, like this:-\n\n    Cache::config('default', array('engine' =\u003e 'File'));\n\n### Step 3\nWhile you have bootstrap.php open, tell Cake to load the plugin like this:-\n\n    CakePlugin::load('Autocache');\n\n### Step 4\nTell your model(s) they $actsAs Autocache by adding this to the top part of the \nmodel definition you want Autocache enabled for.  Alternatively you could just put\nthis into the AppModel.php thus enabling Autocache for all models\n\n    public $actsAs = array('Autocache.Autocache');\n\nNote the Behavior settings possible here in the section below.\n\n### Step 5\nAdd an 'autocache' parameter to your find query, see further below for the various \noptions you have here but it can be as simple as just 'autocache' =\u003e true.\n\n### Step 6\nFire up the AutocachePlugin Tests, they should all pass.\n\n\nUsage\n-----\n\n### Find Parameter Options\n\nThis is the fun stuff, and where Autocache really shines the with its simplicity \nin usage, there are just three options:-\n\n - config (string) = the cache name specified by using a standard Cake\n   Cache::config('a_cache_name', ... )\n\n - name (string) = the developer can override an automatically generated cache \n    key name by specifying it as an option, doing this will give you a small \n    performance gain because we don't have to a serialization and md5 to generate \n    a cache key name - see Q\u0026A below for note on cache key name generation.\n\n - flush (bool) = you can force a reload from the datasource by adding a flush\n   option, which will delete any existing cached value and replace it with a\n   fresh datastore find result.\n\nBecause the 'config' option is the most commonly required option we make it easy\nto access it in the following ways.\n\n - if the 'autocache' option is bool, we use the cache configuration specified when\n   the Autocache Behavior was assigned to the Model, ie the \"default_cache\" parameter\n\n - if the 'autocache' option is a string, we use this string as the cache \n   configuration name to use.\n\n### Find Parameter Option Examples\n\n    $params = array('autocache'=\u003etrue)\n\n    $params = array('autocache'=\u003e'default')\n\n    $params = array('autocache'=\u003earray('config'=\u003e'default'))\n\n    $params = array('autocache'=\u003earray('name'=\u003e'some_name'))\n\n    $params = array('autocache'=\u003earray('flush'=\u003etrue))\n\nThe first three are essentially the same thing expressed differently\n\n### The Model-\u003eautocache_is_from variable\nI've erred about the wisdom of this, non-the-less it's there.  After a result is \nhanded to you from a Model find(), you can check Model-\u003eautocache_is_from \nto determine if the result was from cache or not.  Beware, if you want a portable \nModel code you'll need to do an isset() to test for variable existence because if\nthe behavior is not there the variable will not be set...\n\n### Autocache Behavior Settings\n\n - cache_config_name_default \u003c\u003c defines the default cache configuration name to \n   use when a find query contains an 'autocache' parameter without an explicit \n   cache configuration name.  By default the name is 'default'\n\n - cache_config_name_check \u003c\u003c tells Autocache to check if the cache configuration \n   name that is about to be used has actually been defined, this helps you prevent \n   silly mistakes.  By default this parameter sets itself to true when \n   Configure::read('debug') is greater than 0 and otherwise false.  There may be\n   a small speed improvement in setting this to false.\n\n - dummy_datasource \u003c\u003c defines the dummy datastore name that needs to be\n   defined in your database.php file. By default it's named 'autocache' and it's \n   pretty unlikely you'd ever need to change this.\n\n### Autocache Behavior Setting Examples\n\nFrom the model:-\n\n    $actsAs = array('Autocache.Autocache')\n\n    $actsAs = array('Autocache.Autocache',array('default_cache'=\u003e'level_1'));\n\n    $actsAs = array('Autocache.Autocache',array('default_cache'=\u003e'level_1','check_cache'=\u003efalse));\n\nFrom the Controller through a Behavior \"attach\":-\n\n    $this-\u003eMyModelName-\u003eBehaviors-\u003eattach('Autocache.Autocache',array('default_cache'=\u003e'level_2'));\n\n\nQuestions and Answers\n---------------------\n\nQ: What about cache grouping?\nA: Grouping based on (Model + Cache Config) is a great idea, unfortunately as at\n   CakePHP 2.5.7 it does not *seem* possible since after the initial call to\n   Cache::config() it is not possible to define new groups.  The work-around for\n   this is to implement per-group configs, however, if you do this calls to\n   Cache::clear() appear to cause subsequent calls to Cache::write() to not write\n   to the (FileEngine) cache - I'd really like to be shown wrong on this, more time\n   required to nut out a solution, cache grouping is a good thing.\n\nQ: I want more control over cache times, cache locations etc.  \nA: It's right in front of you :)  The way to achieve this is to specify a new \n   cache configuration for the \"stuff\" you are wanting to cache.  This allows you\n   to get really funky, create a config that caches in APC while others cache to\n   File and establish different time frames for each, for example:-\n\n    Cache::config('default',  array('engine' =\u003e 'APC', 'duration'=\u003e'60 seconds'));\n    Cache::config('level_05', array('engine' =\u003e 'APC', 'duration'=\u003e'5 second'));\n    Cache::config('level_1',  array('engine' =\u003e 'APC', 'duration'=\u003e'1 minute'));\n    Cache::config('level_2',  array('engine' =\u003e 'APC', 'duration'=\u003e'5 minute'));\n    Cache::config('level_3',  array('engine' =\u003e 'APC', 'duration'=\u003e'30 minute'));\n    Cache::config('level_4',  array('engine' =\u003e 'File','duration'=\u003e'4 hour'));\n    Cache::config('level_5',  array('engine' =\u003e 'File','duration'=\u003e'1 day'));\n\nQ: How does Autocache name cached data?  \nA: Take a look at _generateCacheName() the crux of the matter is that we take\n   the all query parameters, serialize them and take a hash of the result\n   thus ensuring a useful unique name per query - yes, there is overhead in\n   doing this but it's still less than doing a database query!\n\nQ: What's AutocacheSource (ie the DummySource) all about?  \nA: In order to prevent the CakePHP Model class from making a full request to\n   the database when we have a cached result we need a way to quickly cause\n   the find() query to return with nothing so we can re-inject the result\n   in the afterFind() callback - it's unfortunate this behavior requires more\n   than one .php file, but that's the way it is - still much tidier than the\n   previous approach that involved cutting'n'pasting code into the AppModel.\n\nQ: What's the history?  \nA: AutocachePlugin follows on from AutocacheBehavior which was an an improvement \n   on \"Automatic model data caching for CakePHP\" that I wrote a while back.  I\n   borrowed from ideas \"jamienay\" had put forward in his automatic_query_caching\n\nQ: What's different about CakephpAutocachePlugin to CakephpAutocacheBehavior?  \nA: Probably the biggest \"thing\" is the change in the find parameter option name\n   from 'cache' to 'autocache' - yes the option name is longer but it is clearer \n   and better aligns with the rest of naming.  Other stuff includes, there is no\n   need to specify the autocache datasource configuration anymore, we deal with\n   that automatically while it can be overridden via the dummy_datasource parameter.\n   ... the the Plugin is just easier to use!\n","funding_links":[],"categories":["Caching"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndejong%2FCakephpAutocachePlugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndejong%2FCakephpAutocachePlugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndejong%2FCakephpAutocachePlugin/lists"}