Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 9f6f9e7

Browse files
committed
Added phpfastcache_bins setting
1 parent d61a457 commit 9f6f9e7

File tree

4 files changed

+75
-28
lines changed

4 files changed

+75
-28
lines changed

‎config/install/phpfastcache.settings.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ phpfastcache_enabled: false
22
phpfastcache_default_ttl: 900
33
phpfastcache_htaccess: true
44
phpfastcache_default_driver: files
5+
phpfastcache_bins: ['bootstrap', 'menu', 'discovery']
56
phpfastcache_drivers_config:
67
apc: []
78
apcu: []

‎src/Cache/PhpFastCacheBackend.php‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,7 @@ class PhpFastCacheBackend implements \Drupal\Core\Cache\CacheBackendInterface
3434
*/
3535
protected $binPrefix;
3636

37-
/**
38-
* The cache tags checksum provider.
39-
*
40-
* @var \Drupal\Core\Cache\CacheTagsChecksumInterface
41-
*/
42-
/* protected $checksumProvider;*/
43-
44-
public function __construct($bin, $cachePool/*, CacheTagsChecksumInterface $checksum_provider*/)
37+
public function __construct($bin, $cachePool)
4538
{
4639
/**
4740
* Constructs a new ApcuBackend instance.

‎src/Cache/PhpFastCacheBackendFactory.php‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Drupal\phpfastcache\Cache;
33

4+
use Drupal\Core\Cache\CacheFactoryInterface;
45
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
56
use phpFastCache\CacheManager;
67
use Drupal\Core\Database\Connection;
@@ -9,8 +10,14 @@
910
/**
1011
* Class PhpFastCacheService
1112
*/
12-
class PhpFastCacheBackendFactory implements \Drupal\Core\Cache\CacheFactoryInterface
13+
class PhpFastCacheBackendFactory implements CacheFactoryInterface
1314
{
15+
/**
16+
* Cache collector for debug purposes
17+
* @var array
18+
*/
19+
protected $cacheCollector = [];
20+
1421
/**
1522
* @var ExtendedCacheItemPoolInterface
1623
*/
@@ -81,7 +88,14 @@ public function __construct(Connection $connection)
8188
*/
8289
protected function getPhpFastCacheInstance()
8390
{
84-
$options = ['ignoreSymfonyNotice' => true];
91+
/**
92+
* Global options
93+
*/
94+
$options = [
95+
'ignoreSymfonyNotice' => true,
96+
'defaultTtl' => $this->settings['phpfastcache_default_ttl'],
97+
];
98+
8599
$driverName = $this->settings['phpfastcache_default_driver'];
86100
$driversConfig = $this->settings['phpfastcache_drivers_config'];
87101

@@ -122,6 +136,7 @@ protected function getPhpFastCacheInstance()
122136
case 'sqlite':
123137
case 'level':
124138
$instance = CacheManager::getInstance($driverName, array_merge($options, [
139+
'htaccess' => $this->settings['phpfastcache_htaccess'],
125140
'path' => $driversConfig[$driverName]['path'],
126141
'securityKey' => $driversConfig[$driverName]['path']['security_key'],
127142
]));
@@ -198,15 +213,19 @@ protected function getSettingsFromDatabase()
198213
}
199214

200215
/**
201-
* Gets ApcuBackend for the specified cache bin.
216+
* Gets PhpFastCacheBackend for the specified cache bin.
202217
*
203-
* @param $bin
218+
* @param string $bin
204219
* The cache bin for which the object is created.
205220
*
206-
* @return \Drupal\Core\Cache\ApcuBackend
221+
* @return \Drupal\phpfastcache\Cache\PhpFastCacheBackend|\Drupal\phpfastcache\Cache\PhpFastCacheVoidBackend
207222
* The cache backend object for the specified cache bin.
208223
*/
209224
public function get($bin) {
210-
return new $this->backendClass($bin, $this->cachePool/*, $this->checksumProvider*/);
225+
if(in_array($bin, $this->settings['phpfastcache_bins'])){
226+
return new $this->backendClass($bin, $this->cachePool);
227+
}else{
228+
return new PhpFastCacheVoidBackend($bin, $this->cachePool);
229+
}
211230
}
212231
}

‎src/Form/PhpFastCacheAdminSettingsForm.php‎

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,10 @@ public function buildForm(array $form, FormStateInterface $form_state) {
8585
'#default_value' => (int) $config->get('phpfastcache_default_ttl'),
8686
'#description' => $this->t('Enable or disable all the PhpFastCache components'),
8787
'#required' => TRUE,
88-
'#title' => $this->t('PhpFastCache default <abbr title="Time to live">TTL</abbr>'),
88+
'#title' => $this->t('Default <abbr title="Time to live">TTL</abbr>'),
8989
'#type' => 'textfield',
9090
];
9191

92-
$form[ 'general' ][ 'phpfastcache_settings_wrapper' ][ 'phpfastcache_htaccess' ] = [
93-
'#default_value' => (bool) $config->get('phpfastcache_htaccess'),
94-
'#description' => $this->t('Automatically generate htaccess for files-based drivers such as Files, Sqlite, etc.'),
95-
'#required' => TRUE,
96-
'#options' => [
97-
'0' => t('No'),
98-
'1' => t('Yes'),
99-
],
100-
'#title' => $this->t('PhpFastCache auto-htaccess generation'),
101-
'#type' => 'select',
102-
];
103-
10492
$driversOption = [];
10593
foreach (CacheManager::getStaticSystemDrivers() as $systemDriver) {
10694
$driversOption[ strtolower($systemDriver) ] = t(ucfirst($systemDriver));
@@ -112,8 +100,53 @@ public function buildForm(array $form, FormStateInterface $form_state) {
112100
'#description' => $this->t('Enable or disable all the PhpFastCache components'),
113101
'#required' => TRUE,
114102
'#options' => $driversOption,
115-
'#title' => $this->t('PhpFastCache driver'),
103+
'#title' => $this->t('Cache driver'),
104+
'#type' => 'select',
105+
];
106+
107+
$form[ 'general' ][ 'phpfastcache_settings_wrapper' ][ 'phpfastcache_htaccess' ] = [
108+
'#default_value' => (bool) $config->get('phpfastcache_htaccess'),
109+
'#description' => $this->t('Automatically generate htaccess for files-based drivers such as Files, Sqlite and Leveldb.'),
110+
'#required' => TRUE,
111+
'#options' => [
112+
'0' => t('No'),
113+
'1' => t('Yes'),
114+
],
115+
'#title' => $this->t('Auto-htaccess generation'),
116116
'#type' => 'select',
117+
'#states' => [
118+
'visible' => [
119+
'select[name="phpfastcache_default_driver"]' => [
120+
['value' => 'files'],
121+
['value' => 'sqlite'],
122+
['value' => 'leveldb']
123+
],
124+
],
125+
],
126+
];
127+
128+
129+
$binDescCallback = function($binName, $binDesc = '')
130+
{
131+
return '<span>' . t(ucfirst($binName)) . '</span>' . ($binDesc ? '&nbsp;-&nbsp;<small>' . t($binDesc) . '</small>' : '');
132+
};
133+
134+
$form[ 'general' ][ 'phpfastcache_settings_wrapper' ][ 'phpfastcache_bins' ] = [
135+
'#default_value' => (array) $config->get('phpfastcache_bins'),
136+
'#description' => 'See /core/core.services.yml for more information about bin uses',
137+
'#required' => false,
138+
'#options' => [
139+
'default' => $binDescCallback('default', 'Default bin if not specified by modules/core'),
140+
'menu' => $binDescCallback('menu', 'Menu tree/items'),
141+
'bootstrap' => $binDescCallback('bootstrap', 'Drupal bootstrap/core initialization'),
142+
'render' => $binDescCallback('render', 'You must expect the cache size to grow up quickly, make sure that the driver you choose have enough memory/disk space.'),
143+
'config' => $binDescCallback('config', 'You will have to purge the cache after each settings changes'),
144+
'dynamic_page_cache' => $binDescCallback('dynamic page cache', ''),
145+
'entity' => $binDescCallback('entity', 'You will have to purge the cache after each entity changes'),
146+
'discovery' => $binDescCallback('discovery', 'Used for plugin manager, entity type manager, field manager, etc.'),
147+
],
148+
'#title' => $this->t('Bins handled by PhpFastCache'),
149+
'#type' => 'checkboxes',
117150
];
118151

119152
/***********************
@@ -330,6 +363,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
330363
->set('phpfastcache_default_ttl', (int) $form_state->getValue('phpfastcache_default_ttl'))
331364
->set('phpfastcache_htaccess', (bool) $form_state->getValue('phpfastcache_htaccess'))
332365
->set('phpfastcache_default_driver', (string) $form_state->getValue('phpfastcache_default_driver'))
366+
->set('phpfastcache_bins', array_values(array_filter((array) $form_state->getValue('phpfastcache_bins'))))
333367
/*****************
334368
* Drivers settings
335369
*****************/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /