laravel-geoip icon indicating copy to clipboard operation
laravel-geoip copied to clipboard

This cache store does not support tagging.

Open hongyukeji opened this issue 5 years ago • 13 comments

src/Cache.php 32 row add code

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

hongyukeji avatar Aug 13 '19 10:08 hongyukeji

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

radwanic avatar Sep 05 '19 13:09 radwanic

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' => [],

radwanic avatar Sep 05 '19 15:09 radwanic

What version of Laravel are you using?

Torann avatar Sep 05 '19 15:09 Torann

@Torann I'm using LV 5.8

radwanic avatar Sep 05 '19 16:09 radwanic

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.

Torann avatar Sep 05 '19 16:09 Torann

@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

radwanic avatar Sep 05 '19 16:09 radwanic

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

Torann avatar Sep 05 '19 19:09 Torann

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

djunehor avatar Nov 10 '19 17:11 djunehor

Another quick change in geoip.php:

'cache_tags' => env('CACHE_DRIVER', 'array') === "file" ? [] : ['torann-geoip-location'],

Shipu avatar Jan 08 '20 17:01 Shipu

@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!

chuck-wood avatar Aug 11 '20 00:08 chuck-wood

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'
    ],

KieronWiltshire avatar Feb 07 '21 19:02 KieronWiltshire

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 :-)

Torann avatar Feb 08 '21 17:02 Torann

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,

a-vasyukov avatar Aug 19 '22 18:08 a-vasyukov