Doug Barth wrote:
> Hello,
> 
> We ran into an issue where the semantics for incrementing or
> decrementing a value in the Rails generic cache vary based on which
> store you are using. I'd like to work up a patch, but I want to
> solicit some opinions on the best way to implement the changes.
> 
> We were attempting to implement the delete by namespace pattern that
> memcached recommends [1]. In short, you keep a counter in a namespace
> key and use the value in your target cache keys. When you want to
> delete the namespace, you increment the key, effectively forgetting
> the previous versions.
> 
> We found that implementing this pattern required custom code for each
> store.
> 
> The MemoryStore will pass the following test case and is what I assume
> is the expected behavior.
> 
>   def test_increment
>     @cache.write('foo', 1)
>     assert_equal 1, @cache.read('foo')
>     assert_equal 2, @cache.increment('foo')
>     assert_equal 2, @cache.read('foo')
>   end
> 
> The FileStore will fail the above test because increment always
> returns 1, not the new value. Is increment expected to return the new
> value?

That seems like a reasonable assumption, it appears the current return
values are just an artifact of the current implementations.


>   def test_increment
>     @cache.write('foo', '1', :raw => true)
>     assert_equal '1', @cache.read('foo', :raw => true)
>     assert_equal 2, @cache.increment('foo')
>     assert_equal '2', @cache.read('foo', :raw => true)
>   end

That's just nasty...  I assume someone's pinged Eric about the bug? I'm
hesitant to take unofficial upstream patches unless memcache-client is
'officially' not getting any more updates.  If there's some reason for
the patches not to be merged I'd hate to pull them and have our own fork
to maintain.

> What are the expected semantics for the cache store facade? I can work
> up a patch with test cases to ensure that the current implementations
> fall in line. My own suggestion would be to mimic the memory store
> test case, with the exception that :raw => true should be supplied
> (and presumably ignored by every impl other than memcache).
> 
>   def test_increment
>     @cache.write('foo', 1, :raw => true)
>     assert_equal 1, @cache.read('foo', :raw => true)
>     assert_equal 2, @cache.increment('foo')
>     assert_equal 2, @cache.read('foo', :raw => true)
>   end

This seems like a good api, if you can make the changes and send a
patch, we can apply it.  Obviously the memcache-client bug is another
issue but hopefully that can be resolved too.


--
Cheers,

Koz


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to