Skip to content

Commit c4ecfd6

Browse files
committed
Allow auto-detect for autoClearCache config.
1 parent 9246de7 commit c4ecfd6

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

docs/Authentication.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,12 @@ Once you move such a code based rule into the INI file, you can safely remove th
8585
## Caching
8686

8787
TinyAuth makes heavy use of caching to achieve optimal performance.
88+
By default it will not use caching in debug mode, though.
8889

89-
You may however want to disable caching while developing to prevent
90-
confusing (outdated) results.
91-
92-
To disable caching either:
93-
94-
- pass ``true`` to the ``autoClearCache`` configuration option
95-
- use the example below to disable caching automatically for CakePHP debug mode
96-
90+
To modify the caching behavior set the ``autoClearCache`` configuration option:
9791
```php
9892
$this->loadComponent('TinyAuth.Auth', [
99-
'autoClearCache' => Configure::read('debug')
93+
'autoClearCache' => true|false
10094
)]
10195
```
10296

docs/Authorization.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,10 @@ view, edit = user
198198
TinyAuth makes heavy use of caching to achieve optimal performance.
199199
By default it will not use caching in debug mode, though.
200200

201-
You may however want to disable caching while developing RBAC to prevent
202-
confusing (outdated) results.
203-
204-
To disable caching either:
205-
206-
- pass ``true`` to the ``autoClearCache`` configuration option
207-
- use the example below to disable caching automatically for CakePHP debug mode
208-
201+
To modify the caching behavior set the ``autoClearCache`` configuration option:
209202
```php
210203
'TinyAuth.Tiny' => [
211-
'autoClearCache' => Configure::read('debug')
204+
'autoClearCache' => true|false
212205
]
213206
```
214207

src/Auth/TinyAuthorize.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class TinyAuthorize extends BaseAuthorize {
6969
'adminPrefix' => 'admin', // name of the admin prefix route (only used when allowUser is enabled)
7070
'cache' => '_cake_core_',
7171
'cacheKey' => 'tiny_auth_acl',
72-
'autoClearCache' => false, // Set to true to delete cache automatically in debug mode
72+
'autoClearCache' => null, // Set to true to delete cache automatically in debug mode, keep null for auto-detect
7373
'aclPath' => null, // @deprecated Use filePath
7474
'filePath' => null, // Possible to locate ini file at given path e.g. Plugin::configPath('Admin')
7575
'file' => 'acl.ini',
@@ -93,6 +93,10 @@ public function __construct(ComponentRegistry $registry, array $config = []) {
9393
throw new Exception(sprintf('Invalid TinyAuthorization cache `%s`', $config['cache']));
9494
}
9595

96+
if ($this->_config['autoClearCache'] === null) {
97+
$this->_config['autoClearCache'] = Configure::read('debug');
98+
}
99+
96100
// BC only
97101
if (isset($this->_config['aclPath'])) {
98102
$this->_config['filePath'] = $this->_config['aclPath'];

src/Controller/Component/AuthComponent.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AuthComponent extends CakeAuthComponent {
2121
protected $_defaultTinyAuthConfig = [
2222
'cache' => '_cake_core_',
2323
'cacheKey' => 'tiny_auth_allow',
24-
'autoClearCache' => false, // Set to true to delete cache automatically in debug mode
24+
'autoClearCache' => null, // Set to true to delete cache automatically in debug mode, keep null for auto-detect
2525
'filePath' => null, // Possible to locate ini file at given path e.g. Plugin::configPath('Admin')
2626
'file' => 'auth_allow.ini',
2727
];
@@ -39,6 +39,10 @@ public function __construct(ComponentRegistry $registry, array $config = []) {
3939
if (!in_array($config['cache'], Cache::configured())) {
4040
throw new Exception(sprintf('Invalid TinyAuth cache `%s`', $config['cache']));
4141
}
42+
43+
if ($this->_config['autoClearCache'] === null) {
44+
$this->_config['autoClearCache'] = Configure::read('debug');
45+
}
4246
}
4347

4448
/**

0 commit comments

Comments
 (0)