@@ -85,7 +85,12 @@ class GraphHandler extends
85
85
*/
86
86
const OPTION_EDGE_DEFINITIONS = 'edgeDefinitions ' ;
87
87
88
- /**
88
+ /**
89
+ * GraphHandler cache store
90
+ */
91
+ protected $ cache ;
92
+
93
+ /**
89
94
* Create a graph
90
95
*
91
96
* This will create a graph using the given graph object and return an array of the created graph object's attributes.<br><br>
@@ -348,7 +353,14 @@ public function deleteOrphanCollection($graph, $orphanCollection, $dropCollectio
348
353
*
349
354
*
350
355
* @param mixed $graph - graph name as a string or instance of Graph
351
- * @param array $options
356
+ * @param array $options - optional, an array of options
357
+ * <p>Options are :<br>
358
+ * <li>'excludeOrphans' - boolean value: true to exclude the orphans or false to include orphans in the result.<br>
359
+ * Defaults to false</li>
360
+ * <li>'_noCache' - boolean: true to not use the handler's cache for looking up prior fetched results.<br>
361
+ * This will also not store the result of this call to the cache.<br>
362
+ * or false to use the cache.</li>
363
+ * </p>
352
364
*
353
365
* @return array
354
366
* @throws ClientException@since 2.2
@@ -359,12 +371,33 @@ public function getVertexCollections($graph, array $options = [])
359
371
$ graph = $ graph ->getKey ();
360
372
}
361
373
362
- $ url = UrlHelper::buildUrl (Urls::URL_GRAPH , [$ graph , Urls::URLPART_VERTEX ]);
374
+ $ excludeOrphans = false ;
375
+ $ _noCache = false ;
376
+
377
+ if ((bool ) $ options ){
378
+ if (isset ($ options ['excludeOrphans ' ]) && !is_bool ($ options ['excludeOrphans ' ])){
379
+ $ excludeOrphans = UrlHelper::getBoolString ($ options ['excludeOrphans ' ]);
380
+ }
381
+
382
+ if (isset ($ options ['_noCache ' ])){
383
+ $ _noCache = $ options ['_noCache ' ];
384
+ }
385
+ }
363
386
364
- if (is_array ($ options ) && isset ($ options ['excludeOrphans ' ])) {
365
- $ url = UrlHelper::appendParamsUrl ($ url , ['excludeOrphans ' => UrlHelper::getBoolString ($ options ['excludeOrphans ' ])]);
387
+ if ($ _noCache === false ){
388
+ if ($ excludeOrphans ===true && !empty ($ this ->cache [$ graph ]['excludeOrphans ' ]['result ' ])){
389
+ return $ this ->cache [$ graph ]['excludeOrphans ' ]['result ' ];
390
+ }else if (!empty ($ this ->cache [$ graph ]['result ' ])) {
391
+ return $ this ->cache [$ graph ]['result ' ];
392
+ }
366
393
}
367
394
395
+ $ url = UrlHelper::buildUrl (Urls::URL_GRAPH , [$ graph , Urls::URLPART_VERTEX ]);
396
+
397
+ if ($ excludeOrphans ===true ){
398
+ $ url = UrlHelper::appendParamsUrl ($ url , ['excludeOrphans ' => $ excludeOrphans ]);
399
+ }
400
+
368
401
try {
369
402
$ response = $ this ->getConnection ()->get ($ url );
370
403
} catch (Exception $ e ) {
@@ -373,7 +406,16 @@ public function getVertexCollections($graph, array $options = [])
373
406
374
407
$ data = $ response ->getJson ();
375
408
sort ($ data [self ::OPTION_COLLECTIONS ]);
376
- return $ data [self ::OPTION_COLLECTIONS ];
409
+ $ data = $ data [self ::OPTION_COLLECTIONS ];
410
+
411
+ if (!empty ($ this ->cache [$ graph ]) && (!isset ($ options ['_noCache ' ]) || isset ($ options ['_noCache ' ]) && $ options ['_noCache ' ] === false )){
412
+ if ($ excludeOrphans ===true ){
413
+ $ this ->cache [$ graph ]['excludeOrphans ' ]['result ' ] = $ data ;
414
+ }else {
415
+ $ this ->cache [$ graph ]['result ' ] = $ data ;
416
+ }
417
+ }
418
+ return $ data ;
377
419
}
378
420
379
421
/**
0 commit comments