Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No cache driver consistency. Passing float-type cache-time variable to memcached, results in no cache. #16731

Closed
dave7280 opened this issue Dec 9, 2016 · 1 comment

Comments

@dave7280
Copy link

dave7280 commented Dec 9, 2016

  • Laravel Version: Newest available 5.3.26?
  • PHP Version: Tested on 5.6/7.0
  • Database Driver & Version: -

Description:

When you put float value to Cache::remember function and the cache driver is memcached, the data will not get cached at all.

Howeer when you put float value and the cache driver is file it will work properly.

Steps To Reproduce:

  1. Set cache driver to "file"
  2. Use some caching code with floatval value interval:
 $count = Cache::remember('testdbcache', 0.1, function() {
            return Model::someDBData()
        });

In this case when "file" driver is used, the cache time will be 0.1*60s = 6s. This works okay.

  1. Set cache driver to "memcached"
  2. Use some caching codewith floatval value interval:
 $count = Cache::remember('testdbcache', 0.1, function() {
            return Model::someDBData()
        });

When memcached driver is used, this will result in query not being cached at all. Memcached driver does not support floatval values. It effectivly terminates 0.1 to 0.

Offtopic: why laravel doesn't support caching in seconds? Implementing interval in seconds is part of every possible caching system. There are situations when you need to refresh data more often than one minute. This is very weird, that you force people to make steps like 0.1*60s, in order to get proper caching with seconds interval.

Fix:

class MemcachedStore, modify toTimestamp() to:

  protected function toTimestamp($minutes)
    {
        $minutes = $minutes * 60;
        return $minutes > 0 ? Carbon::now()->addSeconds($minutes)->getTimestamp() : 0;
    }
@themsaid
Copy link
Member

themsaid commented Jan 3, 2017

Thank you, submitted a fix #17106

@themsaid themsaid closed this as completed Jan 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants