Support the ongoing development of Laravel.io →
posted 10 years ago
Cache

I have one strange issue while using Memcached with Laravel. On my local environment I'm using Windows and because there is no Memcached for Windows I use the file cache driver locally. For the production server, we have Memcached installed and I use different config there and use the Memcached driver. The code is the same. Here is my issue with Memcached. Here is one simple code:

$cacheKey = "test_key";       
$hasCache =  Cache::has($cacheKey);
$value = "";
   
if($hasCache)
{
    $value = Cache::get($cacheKey);
}

$isAdded = Cache::add($cacheKey, "test_value", 60); 

$isAdded is always true (it should be true only the first time), so the cache is added, but $hasCache is always false and $value is always empty. It's like the value is deleted right after it is added to the cache

Locally it works fine, the issue appears only on the production server. There are no exceptions thrown. I'm having hard time debugging this, so if anyone had similar issue, I'd appreciate the help :)

Thanks, Andrej

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

andrejmk andrejmk Joined 28 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.