On Tue, Oct 20, 2009 at 10:23 AM, Florent <[email protected]> wrote:
>> My guess is that the plugin currently works the way it does because of
>> the previous issues in marshalling saved model objects (hint, see
>> below).  I think it might be better to keep the current behavior as it
>> is more memory friendly than caching after save.
>
> why would be more friendly to clear the cache after save than set the
> cache ? on memcached side ?

Model objects after saving have more instance variables than when
freshly retrieved from the database.

> to cache after save, on existing key you change only the value (same
> amount of memory allocated), and you don't miss the next find request
> to clear the cache after save, you free memory unless next find
> request where you miss the cache and you put it back on memory
> so I think, it's more application related, both scenarios are fine
> depending the read/write ratio of your app:
> - if it's a heavy-read application, memory will be used entirely
> because the cache will be clear rarely
> - if it's a heavy-write application, you can afford to miss the cache
> too often otherwise your cache is useless

A heavy-write application doesn't benefit much from caching anyway, so
there's little point in trying to optimize for the heavy-write case,
IMO.  Certainly the default plugin should be optimized for the
heavy-read case.

>> That error comes from the fact that Sequel::Model::Errors is a
>> subclass of Hash that uses a default proc.  It can be reprogrammed to
>> not use a default proc, but it still fails when marshalling @this,
>> which is a dataset that has a singleton class (as all model datasets
>> and many regular datasets do).  I just pushed a commit that fixes
>> these issues, allowing you to marshal saved model objects (http://
>> github.com/jeremyevans/sequel/commit/
>> c12d3fa5b0e51261dafe95383ad8a36583297d35).
>>
>
> when I set the cache with saved model it's working, but when I try to
> retrieve it:
> TypeError: class Sequel::Postgres::Dataset needs to have method
> `_load'
>        from /usr/lib/ruby/gems/1.8/gems/memcached-0.17.3/lib/
> memcached/memcached.rb:365:in `load'
>        from /usr/lib/ruby/gems/1.8/gems/memcached-0.17.3/lib/
> memcached/memcached.rb:365:in `get'
>        from (irb):16
>        from :0
>
> I can put it in the gist if you want

Ah, obviously my lack of experience with ruby's marshalling has shown
through.  It makes sense to me now why it fails, but unfortunately I
can't think of an easy to to fix it without overriding Model#_dump and
Model._load to not attempt to serialize @this (which is not something
I want to attempt).   I should probably revert at least that part of
the commit.

My proposed fix is to add a Model#serializable! method that removes
everything that would not be serializable.  You'd have to call this
first before attempting to serialize a model object safely.  Thoughts?

Jeremy

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" 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/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to