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.7 Red Velvet API

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

  • CacheShell
  • CommandListShell
  • CompletionShell
  • I18nShell
  • OrmCacheShell
  • PluginShell
  • RoutesShell
  • SchemaCacheShell
  • ServerShell
  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.3.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Shell;
 16: 
 17: use Cake\Cache\Cache;
 18: use Cake\Cache\Engine\ApcuEngine;
 19: use Cake\Cache\Engine\WincacheEngine;
 20: use Cake\Console\Shell;
 21: use InvalidArgumentException;
 22: 
 23: /**
 24:  * Cache Shell.
 25:  *
 26:  * Provides a CLI interface to clear caches.
 27:  * This tool can be used in development or by deployment scripts when changes
 28:  * are made that require cached data to be removed.
 29:  */
 30: class CacheShell extends Shell
 31: {
 32: 
 33:     /**
 34:      * Get the option parser for this shell.
 35:      *
 36:      * @return \Cake\Console\ConsoleOptionParser
 37:      */
 38:     public function getOptionParser()
 39:     {
 40:         $parser = parent::getOptionParser();
 41:         $parser->addSubcommand('list_prefixes', [
 42:             'help' => 'Show a list of all defined cache prefixes.',
 43:         ]);
 44:         $parser->addSubcommand('clear_all', [
 45:             'help' => 'Clear all caches.',
 46:         ]);
 47:         $parser->addSubcommand('clear', [
 48:             'help' => 'Clear the cache for a specified prefix.',
 49:             'parser' => [
 50:                 'description' => [
 51:                     'Clear the cache for a particular prefix.',
 52:                     'For example, `cake cache clear _cake_model_` will clear the model cache',
 53:                     'Use `cake cache list_prefixes` to list available prefixes'
 54:                 ],
 55:                 'arguments' => [
 56:                     'prefix' => [
 57:                         'help' => 'The cache prefix to be cleared.',
 58:                         'required' => true
 59:                     ]
 60:                 ]
 61:             ]
 62:         ]);
 63: 
 64:         return $parser;
 65:     }
 66: 
 67:     /**
 68:      * Clear metadata.
 69:      *
 70:      * @param string|null $prefix The cache prefix to be cleared.
 71:      * @throws \Cake\Console\Exception\StopException
 72:      * @return void
 73:      */
 74:     public function clear($prefix = null)
 75:     {
 76:         try {
 77:             $engine = Cache::engine($prefix);
 78:             Cache::clear(false, $prefix);
 79:             if ($engine instanceof ApcuEngine) {
 80:                 $this->warn("ApcuEngine detected: Cleared $prefix CLI cache successfully " .
 81:                 "but $prefix web cache must be cleared separately.");
 82:             } elseif ($engine instanceof WincacheEngine) {
 83:                 $this->warn("WincacheEngine detected: Cleared $prefix CLI cache successfully " .
 84:                 "but $prefix web cache must be cleared separately.");
 85:             } else {
 86:                 $this->out("<success>Cleared $prefix cache</success>");
 87:             }
 88:         } catch (InvalidArgumentException $e) {
 89:             $this->abort($e->getMessage());
 90:         }
 91:     }
 92: 
 93:     /**
 94:      * Clear metadata.
 95:      *
 96:      * @return void
 97:      */
 98:     public function clearAll()
 99:     {
100:         $prefixes = Cache::configured();
101:         foreach ($prefixes as $prefix) {
102:             $this->clear($prefix);
103:         }
104:     }
105: 
106:     /**
107:      * Show a list of all defined cache prefixes.
108:      *
109:      * @return void
110:      */
111:     public function listPrefixes()
112:     {
113:         $prefixes = Cache::configured();
114:         foreach ($prefixes as $prefix) {
115:             $this->out($prefix);
116:         }
117:     }
118: }
119: 
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