Skip to content

Commit b66b0bb

Browse files
committed
Move to just Laravel cache
1 parent afc8936 commit b66b0bb

File tree

11 files changed

+175
-294
lines changed

11 files changed

+175
-294
lines changed

config/geoip.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,40 +79,41 @@
7979
| Default Cache Driver
8080
|--------------------------------------------------------------------------
8181
|
82-
| Here you may specify the default cache storage that should be used
83-
| by the GeoIP package.
82+
| Here you may specify the type of caching that should be used
83+
| by the package.
8484
|
85-
| Supported: "sync", "session", "laravel"
85+
| Options:
86+
|
87+
| all - All location are cached
88+
| some - Cache only the requesting user
89+
| none - Disable cached
8690
|
8791
*/
8892

89-
'cache' => 'sync',
93+
'cache' => 'all',
9094

9195
/*
9296
|--------------------------------------------------------------------------
93-
| Cache Driver Specific Configuration
97+
| Cache Tags
9498
|--------------------------------------------------------------------------
9599
|
96-
| Here you may configure as many cache stores as you wish. The base class
97-
| name of the driver is used as the driver key.
100+
| Cache tags are not supported when using the file or database cache
101+
| drivers in Laravel. This is done so that only locations can be cleared.
98102
|
99103
*/
100104

101-
'cache_drivers' => [
102-
103-
'sync' => [
104-
'class' => \Torann\GeoIP\Cache\Sync::class,
105-
],
105+
'cache_tags' => ['torann-geoip-location'],
106106

107-
'session' => [
108-
'class' => \Torann\GeoIP\Cache\Session::class,
109-
],
107+
/*
108+
|--------------------------------------------------------------------------
109+
| Cache Expiration
110+
|--------------------------------------------------------------------------
111+
|
112+
| Define how long cached location are valid.
113+
|
114+
*/
110115

111-
'laravel' => [
112-
'class' => \Torann\GeoIP\Cache\Laravel::class,
113-
'expires' => 60,
114-
],
115-
],
116+
'cache_expires' => 30,
116117

117118
/*
118119
|--------------------------------------------------------------------------
@@ -136,7 +137,7 @@
136137
'timezone' => 'America/New_York',
137138
'continent' => 'NA',
138139
'default' => true,
139-
'currency' => null,
140+
'currency' => 'USD',
140141
],
141142

142143
];

src/Cache.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Torann\GeoIP;
4+
5+
use Illuminate\Cache\CacheManager;
6+
7+
class Cache
8+
{
9+
/**
10+
* Instance of cache manager.
11+
*
12+
* @var \Illuminate\Cache\CacheManager
13+
*/
14+
protected $cache;
15+
16+
/**
17+
* Lifetime of the cache.
18+
*
19+
* @var int
20+
*/
21+
protected $expires;
22+
23+
/**
24+
* Create a new cache instance.
25+
*
26+
* @param CacheManager $cache
27+
* @param array $tags
28+
* @param int $expires
29+
*/
30+
public function __construct(CacheManager $cache, $tags, $expires = 30)
31+
{
32+
$this->cache = $tags ? $cache->tags($tags) : $cache;
33+
$this->expires = $expires;
34+
}
35+
36+
/**
37+
* Get an item from the cache.
38+
*
39+
* @param string $name
40+
*
41+
* @return array
42+
*/
43+
public function get($name)
44+
{
45+
$value = $this->cache->get($name);
46+
47+
return is_array($value)
48+
? new Location($value)
49+
: null;
50+
}
51+
52+
/**
53+
* Store an item in cache.
54+
*
55+
* @param string $name
56+
* @param Location $location
57+
*
58+
* @return bool
59+
*/
60+
public function set($name, Location $location)
61+
{
62+
return $this->cache->put($name, $location->toArray(), $this->expires);
63+
}
64+
65+
/**
66+
* Flush cache for tags.
67+
*
68+
* @return bool
69+
*/
70+
public function flush()
71+
{
72+
return $this->cache->flush();
73+
}
74+
}

src/Cache/AbstractCache.php

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/Cache/Laravel.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/Cache/Session.php

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/Cache/Sync.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)