Skip to content

Commit e6a71e3

Browse files
committed
Add maxmind service cache
1 parent aa4a970 commit e6a71e3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Torann/GeoIP/GeoIP.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ private function find($ip = null)
161161
return $this->default_location;
162162
}
163163

164+
private $maxmind;
165+
164166
/**
165167
* Maxmind Service.
166168
*
@@ -171,15 +173,17 @@ private function locate_maxmind($ip)
171173
{
172174
$settings = $this->config->get('geoip.maxmind');
173175

174-
if ($settings['type'] === 'web_service') {
175-
$maxmind = new Client($settings['user_id'], $settings['license_key']);
176-
}
177-
else {
178-
$maxmind = new Reader($settings['database_path']);
176+
if (empty($this->maxmind)) {
177+
if ($settings['type'] === 'web_service') {
178+
$this->maxmind = new Client($settings['user_id'], $settings['license_key']);
179+
}
180+
else {
181+
$this->maxmind = new Reader($settings['database_path']);
182+
}
179183
}
180184

181185
try {
182-
$record = $maxmind->city($ip);
186+
$record = $this->maxmind->city($ip);
183187

184188
$location = array(
185189
"ip" => $ip,

0 commit comments

Comments
 (0)