@@ -43,10 +43,6 @@ public function getIoHost($ak, $bucket)
43
43
{
44
44
list ($ bucketHosts ,) = $ this ->getBucketHosts ($ ak , $ bucket );
45
45
$ ioHosts = $ bucketHosts ['ioHost ' ];
46
- if (count ($ ioHosts ) === 0 ) {
47
- return "" ;
48
- }
49
-
50
46
return $ ioHosts [0 ];
51
47
}
52
48
@@ -85,7 +81,7 @@ private function unmarshalUpToken($uptoken)
85
81
86
82
public function getBucketHosts ($ ak , $ bucket )
87
83
{
88
- $ key = $ this ->scheme . $ ak . $ bucket ;
84
+ $ key = $ this ->scheme . " : $ ak: $ bucket" ;
89
85
90
86
$ bucketHosts = $ this ->getBucketHostsFromCache ($ key );
91
87
if (count ($ bucketHosts ) > 0 ) {
@@ -112,7 +108,7 @@ private function getBucketHostsFromCache($key)
112
108
{
113
109
$ ret = array ();
114
110
if (count ($ this ->hostCache ) === 0 ) {
115
- return $ ret ;
111
+ $ this -> hostCacheFromFile () ;
116
112
}
117
113
118
114
if (!array_key_exists ($ key , $ this ->hostCache )) {
@@ -129,9 +125,36 @@ private function getBucketHostsFromCache($key)
129
125
private function setBucketHostsToCache ($ key , $ val )
130
126
{
131
127
$ this ->hostCache [$ key ] = $ val ;
128
+ $ this ->hostCacheToFile ();
132
129
return ;
133
130
}
134
131
132
+ private function hostCacheFromFile ()
133
+ {
134
+
135
+ $ path = $ this ->hostCacheFilePath ();
136
+ if (!file_exists ($ path )) {
137
+ return ;
138
+ }
139
+
140
+ $ bucketHosts = file_get_contents ($ path );
141
+ $ this ->hostCache = json_decode ($ bucketHosts , true );
142
+ return ;
143
+ }
144
+
145
+ private function hostCacheToFile ()
146
+ {
147
+ $ path = $ this ->hostCacheFilePath ();
148
+ file_put_contents ($ path , json_encode ($ this ->hostCache ), LOCK_EX );
149
+ return ;
150
+ }
151
+
152
+ private function hostCacheFilePath ()
153
+ {
154
+ $ home = getenv ('HOME ' );
155
+ return $ home . '/.qiniu_phpsdk_hostscache.json ' ;
156
+ }
157
+
135
158
/* 请求包:
136
159
* GET /v1/query?ak=<ak>&&bucket=<bucket>
137
160
* 返回包:
0 commit comments