@@ -145,6 +145,13 @@ class Ethplorer {
145
145
146
146
protected $ memUsage = [];
147
147
148
+ /**
149
+ * Token current prices in-memory cache
150
+ *
151
+ * @var array
152
+ */
153
+ protected $ aRates = [];
154
+
148
155
/**
149
156
* Constructor.
150
157
*
@@ -2729,6 +2736,19 @@ public function getTokenPrice30d($address){
2729
2736
return $ result ;
2730
2737
}
2731
2738
2739
+ /**
2740
+ * Reads rates cache to local variable.
2741
+ */
2742
+ protected function getRatesCached ($ update = FALSE ){
2743
+ if (empty ($ this ->aRates ) || $ update ){
2744
+ $ this ->aRates = $ this ->oCache ->get ('rates ' , false , true );
2745
+ if (!is_array ($ this ->aRates )){
2746
+ $ this ->aRates = [];
2747
+ }
2748
+ }
2749
+ return $ this ->aRates ;
2750
+ }
2751
+
2732
2752
public function getTokenPrice ($ address , $ updateCache = FALSE ){
2733
2753
// evxProfiler::checkpoint('getTokenPrice', 'START', 'address=' . $address . ', updateCache=' . ($updateCache ? 'TRUE' : 'FALSE'));
2734
2754
$ result = FALSE ;
@@ -2746,12 +2766,8 @@ public function getTokenPrice($address, $updateCache = FALSE){
2746
2766
$ knownPrice = isset ($ this ->aSettings ['updateRates ' ]) && in_array ($ address , $ this ->aSettings ['updateRates ' ]);
2747
2767
2748
2768
if (!$ isHidden && $ knownPrice ){
2749
- $ cache = 'rates ' ;
2750
- $ rates = $ this ->oCache ->get ($ cache , false , true );
2769
+ $ this ->getRatesCached ();
2751
2770
if ($ updateCache ){
2752
- if (!is_array ($ rates )){
2753
- $ rates = array ();
2754
- }
2755
2771
if (isset ($ this ->aSettings ['currency ' ])){
2756
2772
$ method = 'getCurrencyCurrent ' ;
2757
2773
$ params = array ($ address , 'USD ' );
@@ -2773,25 +2789,21 @@ public function getTokenPrice($address, $updateCache = FALSE){
2773
2789
$ result ['diff30d ' ] = $ pdiff ;
2774
2790
}
2775
2791
}
2776
- $ rates [$ address ] = $ result ;
2777
- $ this ->oCache ->save ($ cache , $ rates );
2792
+ $ this -> aRates [$ address ] = $ result ;
2793
+ $ this ->oCache ->save (' rates ' , $ this -> aRates );
2778
2794
}
2779
2795
}
2780
2796
}
2781
- if (is_array ($ rates ) && isset ($ rates [$ address ])){
2782
- $ result = $ rates [$ address ];
2797
+ if (is_array ($ this -> aRates ) && isset ($ this -> aRates [$ address ])){
2798
+ $ result = $ this -> aRates [$ address ];
2783
2799
}
2784
2800
}
2785
2801
// evxProfiler::checkpoint('getTokenPrice', 'FINISH');
2786
2802
return $ result ;
2787
2803
}
2788
2804
2789
2805
public function getAllTokenPrice (){
2790
- $ cache = 'rates ' ;
2791
- $ rates = $ this ->oCache ->get ($ cache , false , true );
2792
- if (!is_array ($ rates )){
2793
- $ rates = array ();
2794
- }
2806
+ $ this ->getRatesCached ();
2795
2807
if (isset ($ this ->aSettings ['currency ' ])){
2796
2808
$ result = $ this ->_jsonrpcall ($ this ->aSettings ['currency ' ], 'getCurrentPrices ' , array ());
2797
2809
if ($ result && is_array ($ result )){
@@ -2813,16 +2825,16 @@ public function getAllTokenPrice(){
2813
2825
}
2814
2826
}
2815
2827
unset($ aPriceData ['address ' ]);
2816
- $ rates [$ address ] = $ aPriceData ;
2828
+ $ this -> aRates [$ address ] = $ aPriceData ;
2817
2829
}
2818
2830
}
2819
2831
}
2820
- if (is_array ($ rates ) && sizeof ($ rates )){
2821
- $ this ->oCache ->save ($ cache , $ rates );
2832
+ if (is_array ($ this -> aRates ) && sizeof ($ this -> aRates )){
2833
+ $ this ->oCache ->save (' rates ' , $ this -> aRates );
2822
2834
}
2823
2835
}
2824
2836
}
2825
- return $ rates ;
2837
+ return $ this -> aRates ;
2826
2838
}
2827
2839
2828
2840
public function getTokenPriceHistory ($ address , $ period = 0 , $ type = 'daily ' , $ updateCache = FALSE , $ updateFullHistory = FALSE ){
0 commit comments