Skip to content
Snippets Groups Projects
Commit 31b5cc82 authored by jaapjansma's avatar jaapjansma
Browse files

added cache by loading data processor

parent 25833a24
No related branches found
No related tags found
No related merge requests found
......@@ -56,6 +56,11 @@ class CRM_Dataprocessor_BAO_DataProcessor extends CRM_Dataprocessor_DAO_DataProc
* @throws \Exception
*/
public static function dataProcessorToClass($dataProcessor) {
$cache_key = 'dataprocessor_'.$dataProcessor['id'];
$cache = CRM_Dataprocessor_Utils_Cache::singleton();
if ($dataProcessorClass = $cache->get($cache_key)) {
return $dataProcessorClass;
}
$factory = dataprocessor_get_factory();
$dataProcessorClass = $factory->getDataProcessorTypeByName($dataProcessor['type']);
$sources = civicrm_api3('DataProcessorSource', 'get', array('data_processor_id' => $dataProcessor['id'], 'options' => array('limit' => 0)));
......@@ -105,6 +110,7 @@ class CRM_Dataprocessor_BAO_DataProcessor extends CRM_Dataprocessor_DAO_DataProc
}
}
}
$cache->set($cache_key, $dataProcessorClass);
return $dataProcessorClass;
}
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
class CRM_Dataprocessor_Utils_Cache {
/**
* @var CRM_DataProcessor_Utils_Cache
*/
private static $singleton;
/**
* @var \CRM_Utils_Cache_Interface
*/
protected $cache;
private function __construct() {
$this->cache = \CRM_Utils_Cache::create([
'name' => 'dataprocessor',
'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
'prefetch' => FALSE,
]);
}
/**
* @return \CRM_DataProcessor_Utils_Cache
*/
public static function singleton() {
if (!self::$singleton) {
self::$singleton = new CRM_DataProcessor_Utils_Cache();
}
return self::$singleton;
}
/**
* @param $key
* @param null $default
*
* @return mixed
*/
public function get($key, $default=NULL) {
return $this->cache->get($key, $default);
}
/**
* @param $key
* @param $value
* @param null $ttl
*
* @return bool
*/
public function set($key, $value, $ttl=NULL) {
return $this->cache->set($key, $value, $ttl);
}
}
\ No newline at end of file
......@@ -185,7 +185,7 @@ class Api implements OutputInterface, API_ProviderInterface, EventSubscriberInte
protected function getFields($entity, $params) {
$cacheKey = strtolower($entity);
if (isset($params['action'])) {
$cacheKey .= '_'.$params['action'];
$cacheKey .= '_'.strtolower($params['action']);
}
if ($cache = $this->cache->get($cacheKey)) {
return $cache;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment