-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathQueryCacheHandler.php
120 lines (102 loc) · 3.22 KB
/
QueryCacheHandler.php
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* ArangoDB PHP client: AQL query result cache handling
*
* @package ArangoDBClient
* @author Jan Steemann
* @copyright Copyright 2015, triagens GmbH, Cologne, Germany
*/
namespace ArangoDBClient;
class QueryCacheHandler extends Handler
{
/**
* Globally turns on the AQL query result cache
*
* @throws Exception
*/
public function enable()
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE, ['properties']);
$this->getConnection()->put($url, $this->json_encode_wrapper(['mode' => 'on']));
}
/**
* Globally turns off the AQL query result cache
*
* @throws Exception
*/
public function disable()
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE, ['properties']);
$this->getConnection()->put($url, $this->json_encode_wrapper(['mode' => 'off']));
}
/**
* Globally sets the AQL query result cache to demand mode
*
* @throws Exception
*/
public function enableDemandMode()
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE, ['properties']);
$this->getConnection()->put($url, $this->json_encode_wrapper(['mode' => 'demand']));
}
/**
* Clears the AQL query result cache for the current database
*
* @throws Exception
*/
public function clear()
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE, []);
$this->getConnection()->delete($url);
}
/**
* Returns the entries from the query cache in current database
*
* @throws Exception
*
* @return array - entries in query cache
*/
public function getEntries()
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE, ['entries']);
$result = $this->getConnection()->get($url);
return $result->getJson();
}
/**
* Adjusts the global AQL query result cache properties
*
* @throws Exception
*
* @param array $properties - the query result cache properties.
* the following properties can be used:
* - maxResults: maximum number of results
* that the query result cache will hold
* per database
* - mode: turns the query result cache on or off,
* or sets it to demand mode. Possible values are
* "on", "off", or "demand".
*
* @return array
*/
public function setProperties(array $properties)
{
$bodyParams = $properties;
$url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE);
$response = $this->getConnection()->put($url, $this->json_encode_wrapper($bodyParams));
return $response->getJson();
}
/**
* Returns the AQL query result cache properties
*
* @throws Exception
*
* @return array
*/
public function getProperties()
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE);
$response = $this->getConnection()->get($url);
return $response->getJson();
}
}
class_alias(QueryCacheHandler::class, '\triagens\ArangoDb\QueryCacheHandler');