1 <?php
2
3 /**
4 * ArangoDB PHP client: AQL query result cache handling
5 *
6 * @package triagens\ArangoDb
7 * @author Jan Steemann
8 * @copyright Copyright 2015, triagens GmbH, Cologne, Germany
9 */
10
11 namespace triagens\ArangoDb;
12
13 class QueryCacheHandler extends
14 Handler
15 {
16
17 /**
18 * Globally turns on the AQL query result cache
19 *
20 * @throws Exception
21 */
22 public function enable()
23 {
24 $url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE, ['properties']);
25 $this->getConnection()->put($url, $this->json_encode_wrapper(['mode' => 'on']));
26 }
27
28
29 /**
30 * Globally turns off the AQL query result cache
31 *
32 * @throws Exception
33 */
34 public function disable()
35 {
36 $url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE, ['properties']);
37 $this->getConnection()->put($url, $this->json_encode_wrapper(['mode' => 'off']));
38 }
39
40
41 /**
42 * Globally sets the AQL query result cache to demand mode
43 *
44 * @throws Exception
45 */
46 public function enableDemandMode()
47 {
48 $url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE, ['properties']);
49 $this->getConnection()->put($url, $this->json_encode_wrapper(['mode' => 'demand']));
50 }
51
52 /**
53 * Clears the AQL query result cache for the current database
54 *
55 * @throws Exception
56 */
57 public function clear()
58 {
59 $url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE, []);
60 $this->getConnection()->delete($url);
61 }
62
63 /**
64 * Adjusts the global AQL query result cache properties
65 *
66 * @throws Exception
67 *
68 * @param array $properties - the query result cache properties.
69 * the following properties can be used:
70 * - maxResults: maximum number of results
71 * that the query result cache will hold
72 * per database
73 * - mode: turns the query result cache on or off,
74 * or sets it to demand mode. Possible values are
75 * "on", "off", or "demand".
76 *
77 * @return array
78 */
79 public function setProperties(array $properties)
80 {
81 $bodyParams = $properties;
82
83 $url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE);
84 $response = $this->getConnection()->put($url, $this->json_encode_wrapper($bodyParams));
85
86 return $response->getJson();
87 }
88
89 /**
90 * Returns the AQL query result cache properties
91 *
92 * @throws Exception
93 *
94 * @return array
95 */
96 public function getProperties()
97 {
98 $url = UrlHelper::buildUrl(Urls::URL_QUERY_CACHE);
99 $response = $this->getConnection()->get($url);
100
101 return $response->getJson();
102 }
103 }
104