arthurnn / memcached

A Ruby interface to the libmemcached C client
Academic Free License v3.0
432 stars 125 forks source link

Memcached 1.1 breaks compatability with Interlock 1.4 #39

Closed joe1chen closed 13 years ago

joe1chen commented 13 years ago

Hi, I'm running into an issue where the interlock gem no longer works with the memcached gem starting with memcached 1.1.

Here's the error I'm getting:

Expected argument 5 of type time_t, but got ActiveSupport::Duration 600 seconds
    in SWIG method 'memcached_set'

And the view code that caused this looks like:

     -view_cache :tag => :recent_comments_sites, :ttl => 10.minutes do
       =render :partial => 'frontend/sidebar/comment', :collection => @recent_comments

This issue goes away as soon as I downgrade to memcached 1.0.6.

Just by looking at the change history, it looks like this commit was the culprit:

https://github.com/fauna/memcached/commit/6ea7af86e1a6141847ff1cc9100a93644223d517

Any tips on how to fix this would be greatly appreciated.

evan commented 13 years ago

TTLs need to be Fixnums now. Just call .to_i on your 10.minutes, or alternatively, use the time_constants gem.

joe1chen commented 13 years ago

Thanks Evan for the fast response. I was able to change my view code to use 10.minutes.to_i and it works fine. However, there are still some issues with the view_cache code that wasn't passing in a :ttl value. In this case, the default :ttl value is used. The problem is that the default coming back from interlock is 1.day.

From Interlock's config.rb

DEFAULTS = {
    :ttl => 1.day,
    :namespace => 'app',
    :servers => ['127.0.0.1:11211'],
    :client => 'memcache-client',
    :with_finders => false
  }

I guess this means that you are forced to either add :ttl values to all view_cache calls or add a :ttl override in the memcached.yml file.

Perhaps this can be considered a bug in Interlock. Interlock should be fixed so that internally it calls .to_i on the ttl values. This way, it is compatible with memcached gem as well as retaining compatibility with memcache-client as well.

evan commented 13 years ago

Sure; can you send me a pull request for Interlock?