Skip to content

Commit

Permalink
feat: add Config\Optimize::$locatorCacheEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Mar 7, 2024
1 parent a241659 commit 49c4522
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
9 changes: 9 additions & 0 deletions app/Config/Optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ class Optimize
* @see https://codeigniter.com/user_guide/concepts/factories.html#config-caching
*/
public bool $configCacheEnabled = false;

/**
* --------------------------------------------------------------------------
* Config Caching
* --------------------------------------------------------------------------
*
* @see https://codeigniter.com/user_guide/concepts/autoloader.html#file-locator-caching
*/
public bool $locatorCacheEnabled = false;
}
11 changes: 10 additions & 1 deletion system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use CodeIgniter\Autoloader\Autoloader;
use CodeIgniter\Autoloader\FileLocator;
use CodeIgniter\Autoloader\FileLocatorCached;
use CodeIgniter\Autoloader\FileLocatorInterface;
use CodeIgniter\Cache\CacheInterface;
use CodeIgniter\Cache\ResponseCache;
Expand Down Expand Up @@ -71,6 +72,7 @@
use Config\Images;
use Config\Migrations;
use Config\Modules;
use Config\Optimize;
use Config\Pager as ConfigPager;
use Config\Services as AppServices;
use Config\Toolbar as ConfigToolbar;
Expand Down Expand Up @@ -281,7 +283,14 @@ public static function locator(bool $getShared = true)
{
if ($getShared) {
if (empty(static::$instances['locator'])) {
static::$instances['locator'] = new FileLocator(static::autoloader());
$cacheEnabled = class_exists(Optimize::class)
&& (new Optimize())->locatorCacheEnabled;

if ($cacheEnabled) {
static::$instances['locator'] = new FileLocatorCached(new FileLocator(static::autoloader()));
} else {
static::$instances['locator'] = new FileLocator(static::autoloader());
}
}

return static::$mocks['locator'] ?? static::$instances['locator'];
Expand Down
4 changes: 2 additions & 2 deletions user_guide_src/source/concepts/autoloader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,6 @@ Or simply delete the **writable/cache/FileLocatorCache** file.
How to Enable FileLocator Caching
=================================

Add the following code in **app/Config/Services.php**:
Set the following property to ``true`` in **app/Config/Optimize.php**::

.. literalinclude:: autoloader/004.php
public bool $locatorCacheEnabled = true;
25 changes: 0 additions & 25 deletions user_guide_src/source/concepts/autoloader/004.php

This file was deleted.

0 comments on commit 49c4522

Please sign in to comment.