Torann / laravel-geoip

Determine the geographical location of website visitors based on their IP addresses.
http://lyften.com/projects/laravel-geoip
BSD 2-Clause "Simplified" License
2.09k stars 372 forks source link

This cache store does not support tagging. #147

Open hongyukeji opened 5 years ago

hongyukeji commented 5 years ago

src/Cache.php 32 row add code

if (strstr(config('cache.default'), 'file') || strstr(config('cache.default'), 'database')) {
    config(['cache.default' => 'array']);
}
radwanic commented 5 years ago

I'm getting this too. Using redis as a cache driver... @Torann any fixes for that?

radwanic commented 5 years ago

I ended up setting 'cache_tags' as an empty array in geoip.php config file

/*
|--------------------------------------------------------------------------
| Cache Tags
|--------------------------------------------------------------------------
|
| Cache tags are not supported when using the file or database cache
| drivers in Laravel. This is done so that only locations can be cleared.
|
*/

'cache_tags' => [],
Torann commented 5 years ago

What version of Laravel are you using?

radwanic commented 5 years ago

@Torann I'm using LV 5.8

Torann commented 5 years ago

It sounds like you are trying to use caching with GeoIP, but the caching driver you have set as the default for the application doesn't support tagging, which is a requirement for caching to work with GeoIP. I would suggest turning off caching for GeoIP, 'cache' => 'none' and see if that solves it.

radwanic commented 5 years ago

@Torann setting 'cache_tags' => [] insead of 'cache_tags' => ['torann-geoip-location'] in the config file solved the issue. But does that mean it is still caching? As you know caching is essential.

On a side note, the object returned does not contain cached

image

Torann commented 5 years ago

It is not caching. Doing 'cache_tags' => [] is also turning off caching. The error message This cache store does not support tagging is telling you that your application setup for caching does not support tagging, which is required by GeoIP. So in this case you need to disable caching for GeoIP or setup caching for the application that supports tagging. This is explained some in the config file https://github.com/Torann/laravel-geoip/blob/master/config/geoip.php#L122

djunehor commented 4 years ago

Another quick is to change CACHE_DRIVER in .env to CACHE_DRIVER=array

Shipu commented 4 years ago

Another quick change in geoip.php:

'cache_tags' => env('CACHE_DRIVER', 'array') === "file" ? [] : ['torann-geoip-location'],
chuck-wood commented 4 years ago

@Torann I set cache to 'none' and it still attempts to initialize the Cache object, throwing the BadMethodCallException.

I think there should be another check like if ($this->config('cache', 'none') !== 'none') ... around src/GeoIP.php line 88.

Thanks for putting out this package!

KieronWiltshire commented 3 years ago

If anyone is interested in a quick fix for this issue, I use file for local dev and use redis for production/staging. Here is some code I added to the geoip config file

'cache_tags' => (
        strtolower(config('cache.default')) === 'file'
        || strtolower(config('cache.default')) === 'database'
    ) ? [] : [
        'torann-geoip-location'
    ],
Torann commented 3 years ago

I would recommend just turning off caching on your local, or if you're using Homestead just use the Redis built into it. It's better to mirror your production env when developing locally, less likely to run into one offs like this :-)

a-vasyukov commented 2 years ago

I would recommend just turning off caching on your local, or if you're using Homestead just use the Redis built into it. It's better to mirror your production env when developing locally, less likely to run into one offs like this :-)

    'cache_tags' => in_array(config('cache.default'), ['array', 'redis'])
        ? ['torann-geoip-location']
        : null,