diff --git a/CRM/Dataprocessor/BAO/DataProcessor.php b/CRM/Dataprocessor/BAO/DataProcessor.php index 8a526e5f495e77c01dbb2faa07fd440db11300b1..bd500d3a5bfe02f5aa65a2e45e1c9af22ac55d0b 100644 --- a/CRM/Dataprocessor/BAO/DataProcessor.php +++ b/CRM/Dataprocessor/BAO/DataProcessor.php @@ -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; } diff --git a/CRM/Dataprocessor/Utils/Cache.php b/CRM/Dataprocessor/Utils/Cache.php new file mode 100644 index 0000000000000000000000000000000000000000..efcfa0704272985c8a44468700deabce6c432eaa --- /dev/null +++ b/CRM/Dataprocessor/Utils/Cache.php @@ -0,0 +1,58 @@ +<?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 diff --git a/Civi/DataProcessor/Output/Api.php b/Civi/DataProcessor/Output/Api.php index f73283d6baf91e85a88533631979c29526a91f9d..12220270002db6951415f4f9bc98e8499ae7bcd9 100644 --- a/Civi/DataProcessor/Output/Api.php +++ b/Civi/DataProcessor/Output/Api.php @@ -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;