CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 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

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • BaseSchema
  • CachedCollection
  • Collection
  • MysqlSchema
  • PostgresSchema
  • SqliteSchema
  • SqlserverSchema
  • TableSchema

Interfaces

  • SqlGeneratorInterface
  • TableSchemaAwareInterface
  • TableSchemaInterface
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.0.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Database\Schema;
 16: 
 17: use Cake\Cache\Cache;
 18: use Cake\Datasource\ConnectionInterface;
 19: 
 20: /**
 21:  * Extends the schema collection class to provide caching
 22:  */
 23: class CachedCollection extends Collection
 24: {
 25:     /**
 26:      * The name of the cache config key to use for caching table metadata,
 27:      * of false if disabled.
 28:      *
 29:      * @var string|bool
 30:      */
 31:     protected $_cache = false;
 32: 
 33:     /**
 34:      * Constructor.
 35:      *
 36:      * @param \Cake\Datasource\ConnectionInterface $connection The connection instance.
 37:      * @param string|bool $cacheKey The cache key or boolean false to disable caching.
 38:      */
 39:     public function __construct(ConnectionInterface $connection, $cacheKey = true)
 40:     {
 41:         parent::__construct($connection);
 42:         $this->setCacheMetadata($cacheKey);
 43:     }
 44: 
 45:     /**
 46:      * {@inheritDoc}
 47:      *
 48:      */
 49:     public function describe($name, array $options = [])
 50:     {
 51:         $options += ['forceRefresh' => false];
 52:         $cacheConfig = $this->getCacheMetadata();
 53:         $cacheKey = $this->cacheKey($name);
 54: 
 55:         if (!empty($cacheConfig) && !$options['forceRefresh']) {
 56:             $cached = Cache::read($cacheKey, $cacheConfig);
 57:             if ($cached !== false) {
 58:                 return $cached;
 59:             }
 60:         }
 61: 
 62:         $table = parent::describe($name, $options);
 63: 
 64:         if (!empty($cacheConfig)) {
 65:             Cache::write($cacheKey, $table, $cacheConfig);
 66:         }
 67: 
 68:         return $table;
 69:     }
 70: 
 71:     /**
 72:      * Get the cache key for a given name.
 73:      *
 74:      * @param string $name The name to get a cache key for.
 75:      * @return string The cache key.
 76:      */
 77:     public function cacheKey($name)
 78:     {
 79:         return $this->_connection->configName() . '_' . $name;
 80:     }
 81: 
 82:     /**
 83:      * Sets the cache config name to use for caching table metadata, or
 84:      * disables it if false is passed.
 85:      *
 86:      * @param bool $enable Whether or not to enable caching
 87:      * @return $this
 88:      */
 89:     public function setCacheMetadata($enable)
 90:     {
 91:         if ($enable === true) {
 92:             $enable = '_cake_model_';
 93:         }
 94: 
 95:         $this->_cache = $enable;
 96: 
 97:         return $this;
 98:     }
 99: 
100:     /**
101:      * Gets the cache config name to use for caching table metadata, false means disabled.
102:      *
103:      * @return string|bool
104:      */
105:     public function getCacheMetadata()
106:     {
107:         return $this->_cache;
108:     }
109: 
110:     /**
111:      * Sets the cache config name to use for caching table metadata, or
112:      * disables it if false is passed.
113:      * If called with no arguments it returns the current configuration name.
114:      *
115:      * @deprecated 3.4.0 Use setCacheMetadata()/getCacheMetadata()
116:      * @param bool|null $enable Whether or not to enable caching
117:      * @return string|bool
118:      */
119:     public function cacheMetadata($enable = null)
120:     {
121:         deprecationWarning(
122:             'CachedCollection::cacheMetadata() is deprecated. ' .
123:             'Use CachedCollection::setCacheMetadata()/getCacheMetadata() instead.'
124:         );
125:         if ($enable !== null) {
126:             $this->setCacheMetadata($enable);
127:         }
128: 
129:         return $this->getCacheMetadata();
130:     }
131: }
132: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs