Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions classes/engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class engine extends \core_search\engine {
*/
protected $count = 0;

/**
* @var cache_application|cache_session|cache_store The cache storage.
*/
protected $cache = null;

/**
*
* @var array Configuration defaults.
Expand Down Expand Up @@ -87,6 +92,8 @@ public function __construct() {
set_config($name, $value, 'search_elastic');
}

$this->cache = \cache::make('search_elastic', 'elasticserver');

}

/**
Expand Down Expand Up @@ -181,12 +188,19 @@ public function validate_index() {
* @return object Apache Lucene version details.
*/
private function get_es_version_details() {
$url = $this->get_url();
$client = new \search_elastic\esrequest();
$response = $client->get($url);
$responsebody = json_decode($response->getBody());
$data = $this->cache->get('es_version');

if ($data === false) {
$url = $this->get_url();
$client = new \search_elastic\esrequest();
$response = $client->get($url);
$responsebody = json_decode($response->getBody());

$data = $responsebody->version;
$this->cache->set('es_version', $responsebody->version);
}

return $responsebody->version;
return $data;
}

/**
Expand Down
32 changes: 32 additions & 0 deletions db/caches.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Elasticsearch web service external functions and service definitions.
*
* @package search_elastic
* @copyright 2017 Matt Porritt <mattp@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$definitions = [
'elasticserver' => [
'mode' => cache_store::MODE_APPLICATION,
'ttl' => 5 * MINSECS,
]
];
1 change: 1 addition & 0 deletions lang/en/search_elastic.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

$string['pluginname'] = 'Elastic';
$string['pluginname_help'] = 'Search backend for the Elasticsearch search engine';
$string['cachedef_elasticsearch'] = 'Cache server\'s metadata';

$string['addfail'] = 'Failed to add document to index';
$string['advsettings'] = 'Advanced settings';
Expand Down