Thanks for the tip!
On Friday, February 8, 2013 5:02:00 PM UTC-5, Chris Corbyn wrote:
>
> We override accessors and we just invoke super to get the original data.
> So really this should work:
>
> has n, :subjects
>
> def subjects
> Rails.cache.fetch(id) { super }
> end
>
> Cheers,
>
> Chris
>
>
> Il giorno 09/feb/2013, alle ore 04:36, Neil C
> <[email protected]<javascript:>>
> ha scritto:
>
> I am generating a web page that will ultimately display a lot of
> content--perhaps something like 50 categories each with 20 subjects each
> with 10 photos. I am devising a caching strategy both at the database layer
> and the UI layer, but I had a question about the former I want to pose to
> the experts here.
>
> So the association would look something *display.categories.subjects.photos.
> *It seems to me just eyeballing that *display.categories.subjects* will
> be an expensive call I would like to cache.
>
> Imagine the following category model:
>
> class Category
> include DataMapper::Resource
>
> property :id, Serial
> ...
> has n, :subjects
>
> def subjects
> Rails.cache.fetch(self.id) { attribute_get(:subjects) #or something }
> end
> end
>
> Basically I want to override *subjects* so that I grab the cache of it if
> available. Otherwise, execute *subjects* as it
> would normally without the override to return the association from a
> database query.
>
> However, no matter what I try-- attribute_get, super, various combinations
> of each--I can't manage to solve this. I really don't want to have a second
> method to expose the cached association and betray those implementation
> details to my client code.
>
> Any ideas on this are appreciated.
>
> Thanks.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "DataMapper" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected]<javascript:>
> .
> Visit this group at http://groups.google.com/group/datamapper?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/datamapper?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.