-
Notifications
You must be signed in to change notification settings - Fork 1
/
wmpage_cache.module
53 lines (46 loc) · 1.17 KB
/
wmpage_cache.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\wmpage_cache\Dispatcher;
/**
* Implements @see hook_cron()
*/
function wmpage_cache_cron(): void
{
wmpage_cache_cron_purge_expired();
}
/**
* Purge expired wmpage_cache_cache items.
*/
function wmpage_cache_cron_purge_expired(): void
{
$ctr = Drupal::getContainer();
$ctr->get('wmpage_cache.storage')->remove(
$ctr->get('wmpage_cache.storage')->getExpired(
$ctr->getParameter('wmpage_cache.purge_per_cron')
)
);
}
/**
* Implements @see hook_cache_flush().
*/
function wmpage_cache_cache_flush(): void
{
$ctr = \Drupal::getContainer();
if ($ctr->getParameter('wmpage_cache.flush_on_cache_rebuild')) {
$ctr->get('wmpage_cache.storage')->flush();
}
}
/**
* Implements @see hook_page_attachments().
*/
function wmpage_cache_page_attachments(array &$attachments)
{
$dispatcher = \Drupal::getContainer()
->get('wmpage_cache.dispatcher');
if (!$dispatcher instanceof Dispatcher) {
return;
}
$dispatcher->getCacheableMetadata()
->merge(CacheableMetadata::createFromRenderArray($attachments))
->applyTo($attachments);
}