forked from RESTful-Drupal/restful
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restful.cache.inc
79 lines (70 loc) · 3.75 KB
/
restful.cache.inc
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* @file
* Procedural implementations for cache related features.
*/
use Drupal\restful\RenderCache\RenderCache;
/**
* Clears all caches and associated fragments.
*/
function restful_clear_caches() {
/* @var \Drupal\restful\RenderCache\Entity\CacheFragmentController $controller */
$controller = entity_get_controller('cache_fragment');
$controller->wipe();
cache_clear_all('*', RenderCache::CACHE_BIN, TRUE);
drupal_set_message(t('RESTful caches were successfully cleared.'));
}
/**
* Implements hook_flush_caches().
*/
function restful_flush_caches() {
if (!variable_get('restful_clear_on_cc_all', FALSE)) {
return array();
}
// Delete all the cache fragments.
/* @var \Drupal\restful\RenderCache\Entity\CacheFragmentController $controller */
$controller = entity_get_controller('cache_fragment');
$controller->wipe();
return array(RenderCache::CACHE_BIN);
}
/**
* Menu callback; Admin settings form.
*/
function restful_admin_cache_settings($form_state) {
$form = array();
$form['restful_page_cache'] = array(
'#type' => 'checkbox',
'#title' => t('Page cache'),
'#description' => t('RESTful can leverage page cache, this will boost your performace for anonymous traffic. !link to start caching responses. Status: <strong>@status</strong>. <strong>CAUTION:</strong> If your resources are using authentication providers other than cookie, you will want to turn this off. Otherwise you may get cached anonymous values for your authenticated GET requests.', array(
'!link' => l(t('Enable page cache'), 'admin/config/development/performance'),
'@status' => variable_get('cache', FALSE) ? t('Enabled') : t('Disabled'),
)),
'#disabled' => !variable_get('cache', FALSE),
'#default_value' => variable_get('restful_page_cache', FALSE) && variable_get('cache', FALSE),
);
$form['restful_render_cache'] = array(
'#type' => 'checkbox',
'#title' => t('Cache results'),
'#description' => t('When enabled any resource that has not explicitly disabled the caching will be cached. Note that the first hit may result with slower response, although the next ones would be significantly faster. This is different from the page cache in the sense that it acts at the row level (a single entity, a single database row, ...), therefore allowing you to assemble non cached pages with the cached bits faster.'),
'#default_value' => variable_get('restful_render_cache', FALSE),
);
$form['clear_restful'] = array(
'#submit' => array('restful_clear_caches'),
'#type' => 'submit',
'#value' => t('Clear render caches'),
'#disabled' => !variable_get('restful_render_cache', FALSE) && user_access('restful clear render caches'),
);
$form['restful_clear_on_cc_all'] = array(
'#type' => 'checkbox',
'#title' => t('Clear on global flush'),
'#description' => t("Check this box to clear the render caches when clearing Drupal's caches. In general the render caches are more robust than the TTL based caches. The recommended value is unchecked."),
'#default_value' => variable_get('restful_clear_on_cc_all', FALSE),
);
$form['restful_fast_cache_clear'] = array(
'#type' => 'checkbox',
'#title' => t('Fast cache clear'),
'#description' => t('A lot of cache fragment entries may be created by default. This may cause your cache clears to be slow. By checking this checkbox the cache fragments are deleted from the database in a fast manner. As a trade-in, no hook_entity_delete will be fired for the cache fragment entities. This is OK in the vast majority of the cases. You can mitigate the number of generated fragments by overriding the "getCacheContext" method in your data provider.'),
'#default_value' => variable_get('restful_fast_cache_clear', TRUE),
);
return system_settings_form($form);
}