Skip to content

Commit 3e5575d

Browse files
authored
3118995: Adds handler for cache set errors (#16)
fix(library)
1 parent 9c28a77 commit 3e5575d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

patternkit.services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
arguments: ['@patternkit.library.discovery.collector']
1212
patternkit.library.discovery.collector:
1313
class: Drupal\patternkit\PatternLibraryCollector
14-
arguments: ['@cache.discovery', '@config.factory', '@file_system', '@plugin.manager.library.pattern', '@lock', '@module_handler', '@app.root', '@theme.manager']
14+
arguments: ['@cache.discovery', '@config.factory', '@file_system', '@plugin.manager.library.pattern', '@lock', '@logger.channel.default', '@module_handler', '@app.root', '@theme.manager']
1515
tags:
1616
- { name: needs_destruction }
1717
patternkit.library.discovery.parser.file:

src/PatternLibraryCollector.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
1414
use Drupal\Core\Extension\ModuleHandlerInterface;
1515
use Drupal\Core\File\FileSystemInterface;
16+
use Drupal\Core\Logger\LoggerChannelInterface;
1617
use Drupal\Core\Serialization\Yaml;
1718
use Drupal\Core\Theme\ThemeManagerInterface;
1819
use Drupal\patternkit\Form\PatternkitSettingsForm;
@@ -50,6 +51,9 @@ class PatternLibraryCollector extends CacheCollector implements ContainerInjecti
5051
/** @var \Drupal\patternkit\PatternLibraryPluginManager */
5152
protected $libraryPluginManager;
5253

54+
/** @var \Drupal\Core\Logger\LoggerChannelInterface */
55+
protected $logger;
56+
5357
/** @var \Drupal\Core\Extension\ModuleHandlerInterface */
5458
protected $moduleHandler;
5559

@@ -74,6 +78,8 @@ class PatternLibraryCollector extends CacheCollector implements ContainerInjecti
7478
* Provide the file system service.
7579
* @param \Drupal\Core\Lock\LockBackendInterface $lock
7680
* Provide the lock backend.
81+
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger
82+
* Provide the logging channel.
7783
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
7884
* Provide a module handler.
7985
* @param \Drupal\patternkit\PatternLibraryPluginManager $library_plugin_manager
@@ -89,6 +95,7 @@ public function __construct(
8995
FileSystemInterface $file_system,
9096
PatternLibraryPluginManager $library_plugin_manager,
9197
LockBackendInterface $lock,
98+
LoggerChannelInterface $logger,
9299
ModuleHandlerInterface $module_handler,
93100
$root,
94101
ThemeManagerInterface $theme_manager) {
@@ -97,6 +104,7 @@ public function __construct(
97104
$this->config = $this->configFactory->get(PatternkitSettingsForm::SETTINGS);
98105
$this->fileSystem = $file_system;
99106
$this->libraryPluginManager = $library_plugin_manager;
107+
$this->logger = $logger;
100108
$this->moduleHandler = $module_handler;
101109
$this->root = $root;
102110
$this->themeManager = $theme_manager;
@@ -120,6 +128,8 @@ public static function create(ContainerInterface $container): self {
120128
$file_system = $container->get('file_system');
121129
/** @var \Drupal\Core\Lock\LockBackendInterface $lock */
122130
$lock = $container->get('lock');
131+
/** @var \Drupal\Core\Logger\LoggerChannelInterface $logger */
132+
$logger = $container->get('@logger.channel.default');
123133
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
124134
$module_handler = $container->get('module_handler');
125135
/** @var string $root */
@@ -132,6 +142,7 @@ public static function create(ContainerInterface $container): self {
132142
$file_system,
133143
$library_plugin_manager,
134144
$lock,
145+
$logger,
135146
$module_handler,
136147
$root,
137148
$theme_manager);
@@ -159,8 +170,13 @@ public function getLibraryDefinitions(): array {
159170
// (if cache enabled, otherwise just a slow, redundant memcache set).
160171
if ($cache_enabled) {
161172
// Explicit copy of the data into cache_set to avoid implicit copy.
173+
// @todo Evaluate encoding via JSON instead to shrink data size.
162174
$this->cache->set(static::PERSISTENT_CACHE_ID,
163175
$cached_metadata);
176+
$cache = $this->cache->get(static::PERSISTENT_CACHE_ID);
177+
if ($cache->data !== $cached_metadata) {
178+
$this->logger->warning('Error storing Patternkit Library Metadata in cache. Check that memcache or your caching module has be configured correctly.');
179+
}
164180
}
165181
}
166182
return $cached_metadata;

0 commit comments

Comments
 (0)