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

  • 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:      * Get the option parser for this shell.
 34:      *
 35:      * @return \Cake\Console\ConsoleOptionParser
 36:      */
 37:     public function getOptionParser()
 38:     {
 39:         $parser = parent::getOptionParser();
 40:         $parser->addSubcommand('list_prefixes', [
 41:             'help' => 'Show a list of all defined cache prefixes.',
 42:         ]);
 43:         $parser->addSubcommand('clear_all', [
 44:             'help' => 'Clear all caches.',
 45:         ]);
 46:         $parser->addSubcommand('clear', [
 47:             'help' => 'Clear the cache for a specified prefix.',
 48:             'parser' => [
 49:                 'description' => [
 50:                     'Clear the cache for a particular prefix.',
 51:                     'For example, `cake cache clear _cake_model_` will clear the model cache',
 52:                     'Use `cake cache list_prefixes` to list available prefixes'
 53:                 ],
 54:                 'arguments' => [
 55:                     'prefix' => [
 56:                         'help' => 'The cache prefix to be cleared.',
 57:                         'required' => true
 58:                     ]
 59:                 ]
 60:             ]
 61:         ]);
 62: 
 63:         return $parser;
 64:     }
 65: 
 66:     /**
 67:      * Clear metadata.
 68:      *
 69:      * @param string|null $prefix The cache prefix to be cleared.
 70:      * @throws \Cake\Console\Exception\StopException
 71:      * @return void
 72:      */
 73:     public function clear($prefix = null)
 74:     {
 75:         try {
 76:             $engine = Cache::engine($prefix);
 77:             Cache::clear(false, $prefix);
 78:             if ($engine instanceof ApcuEngine) {
 79:                 $this->warn("ApcuEngine detected: Cleared $prefix CLI cache successfully " .
 80:                 "but $prefix web cache must be cleared separately.");
 81:             } elseif ($engine instanceof WincacheEngine) {
 82:                 $this->warn("WincacheEngine detected: Cleared $prefix CLI cache successfully " .
 83:                 "but $prefix web cache must be cleared separately.");
 84:             } else {
 85:                 $this->out("<success>Cleared $prefix cache</success>");
 86:             }
 87:         } catch (InvalidArgumentException $e) {
 88:             $this->abort($e->getMessage());
 89:         }
 90:     }
 91: 
 92:     /**
 93:      * Clear metadata.
 94:      *
 95:      * @return void
 96:      */
 97:     public function clearAll()
 98:     {
 99:         $prefixes = Cache::configured();
100:         foreach ($prefixes as $prefix) {
101:             $this->clear($prefix);
102:         }
103:     }
104: 
105:     /**
106:      * Show a list of all defined cache prefixes.
107:      *
108:      * @return void
109:      */
110:     public function listPrefixes()
111:     {
112:         $prefixes = Cache::configured();
113:         foreach ($prefixes as $prefix) {
114:             $this->out($prefix);
115:         }
116:     }
117: }
118: 
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