representable icon indicating copy to clipboard operation
representable copied to clipboard

Russian Doll Caching

Open gottfrois opened this issue 10 years ago • 4 comments

Is it possible or in the road map?

class Song
  belongs_to :artist
end

class Artist
  has_many :songs
end

class SongRepresenter
  property :artist, extend: ArtistRepresenter
end

class ArtistRepresenter
  property :name
end

Let's imagine I update the song but not the artist. It would be nice to get the serialized artist data from cache instead of going through the entire serialization process again.

What do you think?

gottfrois avatar Nov 26 '15 15:11 gottfrois

Everything's possible, and everything's on the road map. :grimacing:

Looks good to me, but I need to think about what would go into Representable and what is actually the data layers' responsibility.

Not top prio right now, though... we can discuss it here.

apotonick avatar Nov 26 '15 19:11 apotonick

what i'm afraid is that, correct me if i'm wrong, representable generate the json at once, taking all properties and serialize it into json. If we want to have russian doll caching, I would guess we want to store json fragments into cache and fetch it every time we need that data.

But maybe we can leverage the from_json strategy to retreive the cached json and merge it with the rest.

gottfrois avatar Nov 26 '15 23:11 gottfrois

Yes, and no! :grin: Representable as per today calls to_hash on nested representers to serialise them. This step could be saved by leveraging the cached hash. We can also think about changing the way JSON gets rendered and allow concatenating a string instead of the intermediate hash representation.

I'm a bit confused by the from_json? Are we talking about rendering? Or parsing?

apotonick avatar Nov 27 '15 00:11 apotonick

Sounds like a good plan. Talking about rendering, sorry for the confusion :)

gottfrois avatar Nov 27 '15 11:11 gottfrois