Merge pull request #92 from grosser/expires_in

support :expires_in in rails
This commit is contained in:
Evan Weaver 2012-07-05 11:27:06 -07:00
Родитель 94f9188312 a195c508df
Коммит a63a45168b
2 изменённых файлов: 31 добавлений и 3 удалений

Просмотреть файл

@ -95,7 +95,7 @@ class Memcached
# Alternative to #set. Accepts a key, value, and an optional options hash supporting the
# options :raw and :ttl.
def write(key, value, options = {})
set(key, value, options[:ttl] || @default_ttl, options[:raw])
set(key, value, options[:ttl] || options[:expires_in] || @default_ttl, options[:raw])
end
# Wraps Memcached#add so that it doesn't raise.

Просмотреть файл

@ -163,10 +163,38 @@ class RailsTest < Test::Unit::TestCase
end
end
def test_write_with_duration
@cache.write key, @value, :ttl => @duration
def test_write_with_default_duration
# should be do an actual write
@cache.write key, @value
result = @cache.get key
assert_equal @value, result
# should use correct ttl
@cache = Memcached::Rails.new(:servers => @servers, :namespace => @namespace, :default_ttl => 123)
@cache.expects(:set).with(key, @value, 123, nil)
@cache.write key, @value
end
def test_write_with_duration_as_ttl
# should be do an actual write
@cache.write key, @value, :ttl => 123
result = @cache.get key
assert_equal @value, result
# should use correct ttl
@cache.expects(:set).with(key, @value, 123, nil)
@cache.write key, @value, :ttl => 123
end
def test_write_with_duration_as_expires_in
# should be do an actual write
@cache.write key, @value, :expires_in => @duration
result = @cache.get key
assert_equal @value, result
# should use correct ttl
@cache.expects(:set).with(key, @value, 123, nil)
@cache.write key, @value, :expires_in => 123
end
def test_add_with_duration