chg: use adhoc redis implementation for cache as @iglocska suggested

pull/8361/head
Luciano Righetti 2022-05-11 16:37:48 +02:00
parent 60160cf999
commit 83a115e340
3 changed files with 10 additions and 25 deletions

View File

@ -255,10 +255,6 @@ Configure::write('Acl.database', 'default');
* and their setttings. * and their setttings.
*/ */
$engine = 'File'; $engine = 'File';
if (function_exists('apcu_dec') && (PHP_SAPI !== 'cli' || ini_get('apc.enable_cli'))) {
require_once APP . 'Plugin/ApcuCache/Engine/ApcuEngine.php'; // it is not possible to use plugin
$engine = 'Apcu'; // faster version of ApcEngine
}
// In development mode, caches should expire quickly. // In development mode, caches should expire quickly.
$duration = '+999 days'; $duration = '+999 days';
@ -293,11 +289,5 @@ Cache::config('_cake_model_', array(
'duration' => $duration 'duration' => $duration
)); ));
Cache::config('misp_short', array(
'engine' => $engine,
'duration' => '1800', // 30 minutes
'prefix' => 'misp_cache_short_',
));
//Comment the following out if you do not with to use the background workers (not recommended) //Comment the following out if you do not with to use the background workers (not recommended)
require_once dirname(__DIR__) . '/Vendor/autoload.php'; require_once dirname(__DIR__) . '/Vendor/autoload.php';

View File

@ -589,9 +589,10 @@ class Taxonomy extends AppModel
} }
$key = 'taxonomies_cache:tagName=' . $tagName . "&" . "metaOnly=$metaOnly" . "&" . "fullTaxonomy=$fullTaxonomy"; $key = 'taxonomies_cache:tagName=' . $tagName . "&" . "metaOnly=$metaOnly" . "&" . "fullTaxonomy=$fullTaxonomy";
$model = $this; $redis = $this->setupRedisWithException();
$taxonomy = json_decode($redis->get($key), true);
return Cache::remember($key, function () use ($model, $metaOnly, $fullTaxonomy, $splits) { if (!$taxonomy) {
if (isset($splits['value'])) { if (isset($splits['value'])) {
$contain = array( $contain = array(
'TaxonomyPredicate' => array( 'TaxonomyPredicate' => array(
@ -606,7 +607,7 @@ class Taxonomy extends AppModel
'LOWER(TaxonomyEntry.value)' => mb_strtolower($splits['value']), 'LOWER(TaxonomyEntry.value)' => mb_strtolower($splits['value']),
); );
} }
$taxonomy = $model->find('first', array( $taxonomy = $this->find('first', array(
'recursive' => -1, 'recursive' => -1,
'conditions' => array('LOWER(Taxonomy.namespace)' => mb_strtolower($splits['namespace'])), 'conditions' => array('LOWER(Taxonomy.namespace)' => mb_strtolower($splits['namespace'])),
'contain' => $contain 'contain' => $contain
@ -614,8 +615,6 @@ class Taxonomy extends AppModel
if ($metaOnly && !empty($taxonomy)) { if ($metaOnly && !empty($taxonomy)) {
$taxonomy = array('Taxonomy' => $taxonomy['Taxonomy']); $taxonomy = array('Taxonomy' => $taxonomy['Taxonomy']);
} }
return $taxonomy;
} else { } else {
$contain = array('TaxonomyPredicate' => array()); $contain = array('TaxonomyPredicate' => array());
if (!$fullTaxonomy) { if (!$fullTaxonomy) {
@ -623,7 +622,7 @@ class Taxonomy extends AppModel
'LOWER(TaxonomyPredicate.value)' => mb_strtolower($splits['predicate']) 'LOWER(TaxonomyPredicate.value)' => mb_strtolower($splits['predicate'])
); );
} }
$taxonomy = $model->find('first', array( $taxonomy = $this->find('first', array(
'recursive' => -1, 'recursive' => -1,
'conditions' => array('LOWER(Taxonomy.namespace)' => mb_strtolower($splits['namespace'])), 'conditions' => array('LOWER(Taxonomy.namespace)' => mb_strtolower($splits['namespace'])),
'contain' => $contain 'contain' => $contain
@ -631,10 +630,12 @@ class Taxonomy extends AppModel
if ($metaOnly && !empty($taxonomy)) { if ($metaOnly && !empty($taxonomy)) {
$taxonomy = array('Taxonomy' => $taxonomy['Taxonomy']); $taxonomy = array('Taxonomy' => $taxonomy['Taxonomy']);
} }
return $taxonomy;
} }
}, 'misp_short');
$redis->setex($key, 1800, $taxonomy);
}
return $taxonomy;
} }
/** /**

View File

@ -270,12 +270,6 @@ Cache::config('_cake_core_', array(
'duration' => $duration 'duration' => $duration
)); ));
Cache::config('misp_short', array(
'engine' => $engine,
'duration' => '1800', // 30 minutes
'prefix' => 'misp_cache_short_',
));
/** /**
* Configure the cache for model and datasource caches. This cache configuration * Configure the cache for model and datasource caches. This cache configuration
* is used to store schema descriptions, and table listings in connections. * is used to store schema descriptions, and table listings in connections.