@@ -357,9 +357,9 @@ public function deleteOrphanCollection($graph, $orphanCollection, $dropCollectio
357
357
* <p>Options are :<br>
358
358
* <li>'excludeOrphans' - boolean value: true to exclude the orphans or false to include orphans in the result.<br>
359
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>
360
+ * <li>'_useCache ' - boolean: true to use the handler's cache for looking up prior fetched results.<br>
361
+ * or false to not use the cache. This will also not store the result of this call to the cache.<br>
362
+ * Defaults to false .</li>
363
363
* </p>
364
364
*
365
365
* @return array
@@ -372,23 +372,23 @@ public function getVertexCollections($graph, array $options = [])
372
372
}
373
373
374
374
$ excludeOrphans = false ;
375
- $ _noCache = false ;
375
+ $ _useCache = false ;
376
376
377
377
if ((bool ) $ options ){
378
378
if (isset ($ options ['excludeOrphans ' ]) && !is_bool ($ options ['excludeOrphans ' ])){
379
379
$ excludeOrphans = UrlHelper::getBoolString ($ options ['excludeOrphans ' ]);
380
380
}
381
381
382
- if (isset ($ options ['_noCache ' ])){
383
- $ _noCache = $ options ['_noCache ' ];
382
+ if (isset ($ options ['_useCache ' ])){
383
+ $ _useCache = $ options ['_useCache ' ];
384
384
}
385
385
}
386
386
387
- if ($ _noCache === false ){
387
+ if ($ _useCache === true ){
388
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 ' ];
389
+ return $ this ->cache [$ graph ]['excludeOrphans ' ]['vertexCollections ' ];
390
+ }else if (!empty ($ this ->cache [$ graph ]['vertexCollections ' ])) {
391
+ return $ this ->cache [$ graph ]['vertexCollections ' ];
392
392
}
393
393
}
394
394
@@ -408,11 +408,11 @@ public function getVertexCollections($graph, array $options = [])
408
408
sort ($ data [self ::OPTION_COLLECTIONS ]);
409
409
$ data = $ data [self ::OPTION_COLLECTIONS ];
410
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 ;
411
+ if ($ _useCache === true ){
412
+ if ($ excludeOrphans ===true && ! empty ( $ this -> cache [ $ graph ][ ' excludeOrphans ' ][ ' vertexCollections ' ]) ){
413
+ $ this ->cache [$ graph ]['excludeOrphans ' ]['vertexCollections ' ] = $ data ;
414
414
}else {
415
- $ this ->cache [$ graph ]['result ' ] = $ data ;
415
+ $ this ->cache [$ graph ]['vertexCollections ' ] = $ data ;
416
416
}
417
417
}
418
418
return $ data ;
@@ -507,17 +507,33 @@ public function deleteEdgeDefinition($graph, $edgeDefinition, $dropCollection =
507
507
* @throws Exception
508
508
*
509
509
* @param mixed $graph - graph name as a string or instance of Graph
510
+ * @param array $options - optional, an array of options
511
+ * <p>Options are :<br>
512
+ * <li>'_useCache' - boolean: true to use the handler's cache for looking up prior fetched results.<br>
513
+ * or false to not use the cache. This will also not store the result of this call to the cache.<br>
514
+ * Defaults to false.</li>
515
+ * </p>
510
516
*
511
517
* @return []
512
518
* @since 2.2
513
519
*/
514
- public function getEdgeCollections ($ graph )
520
+ public function getEdgeCollections ($ graph, array $ options = [] )
515
521
{
516
522
if ($ graph instanceof Graph) {
517
523
$ graph = $ graph ->getKey ();
518
524
}
519
525
520
- $ url = UrlHelper::buildUrl (Urls::URL_GRAPH , [$ graph , Urls::URLPART_EDGE ]);
526
+ $ _useCache = false ;
527
+
528
+ if ((bool ) $ options && isset ($ options ['_useCache ' ])){
529
+ $ _useCache = $ options ['_useCache ' ];
530
+ }
531
+
532
+ if ($ _useCache === true && !empty ($ this ->cache [$ graph ]['edgeCollections ' ])){
533
+ return $ this ->cache [$ graph ]['edgeCollections ' ];
534
+ }
535
+
536
+ $ url = UrlHelper::buildUrl (Urls::URL_GRAPH , [$ graph , Urls::URLPART_EDGE ]);
521
537
522
538
try {
523
539
$ response = $ this ->getConnection ()->get ($ url );
@@ -526,7 +542,12 @@ public function getEdgeCollections($graph)
526
542
}
527
543
$ data = $ response ->getJson ();
528
544
sort ($ data [self ::OPTION_COLLECTIONS ]);
529
- return $ data [self ::OPTION_COLLECTIONS ];
545
+
546
+ if ($ _useCache === true && !empty ($ this ->cache [$ graph ]['edgeCollections ' ])){
547
+ $ this ->cache [$ graph ]['edgeCollections ' ] = $ data ;
548
+ }
549
+
550
+ return $ data [self ::OPTION_COLLECTIONS ];
530
551
}
531
552
532
553
@@ -605,6 +626,7 @@ public function saveVertex($graph, $document, $collection = null)
605
626
$ collection = $ vertexCollections [0 ];
606
627
}
607
628
}
629
+
608
630
$ data = $ document ->getAll ();
609
631
$ url = UrlHelper::buildUrl (Urls::URL_GRAPH , [$ graph , Urls::URLPART_VERTEX , $ collection ]);
610
632
@@ -663,16 +685,19 @@ public function getVertex($graph, $vertexId, array $options = [], $collection =
663
685
$ vertexId = $ parts [1 ];
664
686
$ collection = $ parts [0 ];
665
687
}
666
- if ($ collection === null ) {
667
- if (count ($ this ->getVertexCollections ($ graph )) !== 1 ) {
668
- throw new ClientException ('A collection must be provided. ' );
669
- }
670
- else if (count ($ this ->getVertexCollections ($ graph )) === 1 ) {
671
- $ collection = $ this ->getVertexCollections ($ graph );
672
- $ collection = $ collection [0 ];
673
- }
674
- }
675
- $ url = UrlHelper::buildUrl (Urls::URL_GRAPH , [$ graph , Urls::URLPART_VERTEX , $ collection , $ vertexId ]);
688
+
689
+ $ vertexCollections = $ this ->getVertexCollections ($ graph );
690
+ $ vertexCollectionsCount = count ($ vertexCollections );
691
+ if ($ collection === null ) {
692
+ if ($ vertexCollectionsCount !== 1 ) {
693
+ throw new ClientException ('A collection must be provided. ' );
694
+ }
695
+ else if ($ vertexCollectionsCount === 1 ) {
696
+ $ collection = $ vertexCollections [0 ];
697
+ }
698
+ }
699
+
700
+ $ url = UrlHelper::buildUrl (Urls::URL_GRAPH , [$ graph , Urls::URLPART_VERTEX , $ collection , $ vertexId ]);
676
701
$ response = $ this ->getConnection ()->get ($ url );
677
702
678
703
$ jsonArray = $ response ->getJson ();
@@ -750,16 +775,19 @@ public function replaceVertex($graph, $vertexId, Document $document, array $opti
750
775
$ vertexId = $ parts [1 ];
751
776
$ collection = $ parts [0 ];
752
777
}
753
- if ($ collection === null ) {
754
- if (count ($ this ->getVertexCollections ($ graph )) !== 1 ) {
755
- throw new ClientException ('A collection must be provided. ' );
756
- }
757
- else if (count ($ this ->getVertexCollections ($ graph )) === 1 ) {
758
- $ collection = $ this ->getVertexCollections ($ graph );
759
- $ collection = $ collection [0 ];
760
- }
761
- }
762
- $ options = array_merge ([self ::OPTION_REVISION => false ], $ options );
778
+
779
+ $ vertexCollections = $ this ->getVertexCollections ($ graph );
780
+ $ vertexCollectionsCount = count ($ vertexCollections );
781
+ if ($ collection === null ) {
782
+ if ($ vertexCollectionsCount !== 1 ) {
783
+ throw new ClientException ('A collection must be provided. ' );
784
+ }
785
+ else if ($ vertexCollectionsCount === 1 ) {
786
+ $ collection = $ vertexCollections [0 ];
787
+ }
788
+ }
789
+
790
+ $ options = array_merge ([self ::OPTION_REVISION => false ], $ options );
763
791
764
792
// This preserves compatibility for the old policy parameter.
765
793
$ params = [];
@@ -843,16 +871,19 @@ public function updateVertex($graph, $vertexId, Document $document, array $optio
843
871
$ vertexId = $ parts [1 ];
844
872
$ collection = $ parts [0 ];
845
873
}
846
- if ($ collection === null ) {
847
- if (count ($ this ->getVertexCollections ($ graph )) !== 1 ) {
848
- throw new ClientException ('A collection must be provided. ' );
849
- }
850
- else if (count ($ this ->getVertexCollections ($ graph )) === 1 ) {
851
- $ collection = $ this ->getVertexCollections ($ graph );
852
- $ collection = $ collection [0 ];
853
- }
854
- }
855
- $ options = array_merge ([self ::OPTION_REVISION => false ], $ options );
874
+
875
+ $ vertexCollections = $ this ->getVertexCollections ($ graph );
876
+ $ vertexCollectionsCount = count ($ vertexCollections );
877
+ if ($ collection === null ) {
878
+ if ($ vertexCollectionsCount !== 1 ) {
879
+ throw new ClientException ('A collection must be provided. ' );
880
+ }
881
+ else if ($ vertexCollectionsCount === 1 ) {
882
+ $ collection = $ vertexCollections [0 ];
883
+ }
884
+ }
885
+
886
+ $ options = array_merge ([self ::OPTION_REVISION => false ], $ options );
856
887
// This preserves compatibility for the old policy parameter.
857
888
$ params = [];
858
889
$ params = $ this ->validateAndIncludeOldSingleParameterInParams (
@@ -921,16 +952,19 @@ public function removeVertex($graph, $vertexId, $revision = null, array $options
921
952
$ vertexId = $ parts [1 ];
922
953
$ collection = $ parts [0 ];
923
954
}
924
- if ($ collection === null ) {
925
- if (count ($ this ->getVertexCollections ($ graph )) !== 1 ) {
926
- throw new ClientException ('A collection must be provided. ' );
927
- }
928
- else if (count ($ this ->getVertexCollections ($ graph )) === 1 ) {
929
- $ collection = $ this ->getVertexCollections ($ graph );
930
- $ collection = $ collection [0 ];
931
- }
932
- }
933
- // This preserves compatibility for the old policy parameter.
955
+
956
+ $ vertexCollections = $ this ->getVertexCollections ($ graph );
957
+ $ vertexCollectionsCount = count ($ vertexCollections );
958
+ if ($ collection === null ) {
959
+ if ($ vertexCollectionsCount !== 1 ) {
960
+ throw new ClientException ('A collection must be provided. ' );
961
+ }
962
+ else if ($ vertexCollectionsCount === 1 ) {
963
+ $ collection = $ vertexCollections [0 ];
964
+ }
965
+ }
966
+
967
+ // This preserves compatibility for the old policy parameter.
934
968
$ params = [];
935
969
$ params = $ this ->validateAndIncludeOldSingleParameterInParams (
936
970
$ options ,
0 commit comments