CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.1 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.1
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
    • Network
      • Email
      • Http
    • Routing
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • ApcEngine
  • FileEngine
  • MemcacheEngine
  • WincacheEngine
  • XcacheEngine
  1: <?php
  2: /**
  3:  * Wincache storage engine for cache.
  4:  *
  5:  * Supports wincache 1.1.0 and higher.
  6:  *
  7:  * PHP 5
  8:  *
  9:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 10:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 11:  *
 12:  * Licensed under The MIT License
 13:  * Redistributions of files must retain the above copyright notice.
 14:  *
 15:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 16:  * @link          http://cakephp.org CakePHP(tm) Project
 17:  * @package       Cake.Cache.Engine
 18:  * @since         CakePHP(tm) v 1.2.0.4933
 19:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 20:  */
 21: 
 22: /**
 23:  * Wincache storage engine for cache
 24:  *
 25:  * @package       Cake.Cache.Engine
 26:  */
 27: class WincacheEngine extends CacheEngine {
 28: 
 29: /**
 30:  * Initialize the Cache Engine
 31:  *
 32:  * Called automatically by the cache frontend
 33:  * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
 34:  *
 35:  * @param array $settings array of setting for the engine
 36:  * @return boolean True if the engine has been successfully initialized, false if not
 37:  * @see CacheEngine::__defaults
 38:  */
 39:     public function init($settings = array()) {
 40:         parent::init(array_merge(array(
 41:             'engine' => 'Wincache',
 42:             'prefix' => Inflector::slug(APP_DIR) . '_'),
 43:         $settings));
 44:         return function_exists('wincache_ucache_info');
 45:     }
 46: 
 47: /**
 48:  * Write data for key into cache
 49:  *
 50:  * @param string $key Identifier for the data
 51:  * @param mixed $value Data to be cached
 52:  * @param integer $duration How long to cache the data, in seconds
 53:  * @return boolean True if the data was successfully cached, false on failure
 54:  */
 55:     public function write($key, $value, $duration) {
 56:         $expires = time() + $duration;
 57: 
 58:         $data = array(
 59:             $key . '_expires' => $expires,
 60:             $key => $value
 61:         );
 62:         $result = wincache_ucache_set($data, null, $duration);
 63:         return empty($result);
 64:     }
 65: 
 66: /**
 67:  * Read a key from the cache
 68:  *
 69:  * @param string $key Identifier for the data
 70:  * @return mixed The cached data, or false if the data doesn't exist, has expired, or if
 71:  *     there was an error fetching it
 72:  */
 73:     public function read($key) {
 74:         $time = time();
 75:         $cachetime = intval(wincache_ucache_get($key . '_expires'));
 76:         if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
 77:             return false;
 78:         }
 79:         return wincache_ucache_get($key);
 80:     }
 81: 
 82: /**
 83:  * Increments the value of an integer cached key
 84:  *
 85:  * @param string $key Identifier for the data
 86:  * @param integer $offset How much to increment
 87:  * @return New incremented value, false otherwise
 88:  */
 89:     public function increment($key, $offset = 1) {
 90:         return wincache_ucache_inc($key, $offset);
 91:     }
 92: 
 93: /**
 94:  * Decrements the value of an integer cached key
 95:  *
 96:  * @param string $key Identifier for the data
 97:  * @param integer $offset How much to subtract
 98:  * @return New decremented value, false otherwise
 99:  */
100:     public function decrement($key, $offset = 1) {
101:         return wincache_ucache_dec($key, $offset);
102:     }
103: 
104: /**
105:  * Delete a key from the cache
106:  *
107:  * @param string $key Identifier for the data
108:  * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
109:  */
110:     public function delete($key) {
111:         return wincache_ucache_delete($key);
112:     }
113: 
114: /**
115:  * Delete all keys from the cache.  This will clear every
116:  * item in the cache matching the cache config prefix.
117:  *
118:  * @param boolean $check If true, nothing will be cleared, as entries will
119:  *   naturally expire in wincache..
120:  * @return boolean True Returns true.
121:  */
122:     public function clear($check) {
123:         if ($check) {
124:             return true;
125:         }
126:         $info = wincache_ucache_info();
127:         $cacheKeys = $info['ucache_entries'];
128:         unset($info);
129:         foreach ($cacheKeys as $key) {
130:             if (strpos($key['key_name'], $this->settings['prefix']) === 0) {
131:                 wincache_ucache_delete($key['key_name']);
132:             }
133:         }
134:         return true;
135:     }
136: 
137: }
138: 
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs