Re: [DataMapper] Override Accessor To Hide Caching

2013-02-09 Thread Neil C
Just discovered an issue with the way I am trying to apply criteria. So to 
take your snippet from before, how would I implement something like 
subjects(:name=DM)?

I tried this:

def subjects(criteria_hash = {})
Rails.cache.fetch(my-key) { super(criteria_hash) }
end

But I get a stack overflow in IRB. 

I'm sure this is something simple, but I could use a pointer.

Thanks.


On Friday, February 8, 2013 9:15:28 PM UTC-5, Neil C wrote:

 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 ne...@vidyasource.com 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 datamapper+...@googlegroups.com.
 To post to this group, send email to datam...@googlegroups.com.
 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 datamapper+unsubscr...@googlegroups.com.
To post to this group, send email to datamapper@googlegroups.com.
Visit this group at http://groups.google.com/group/datamapper?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [DataMapper] Override Accessor To Hide Caching

2013-02-08 Thread Chris Corbyn
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 n...@vidyasource.com 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 datamapper+unsubscr...@googlegroups.com.
 To post to this group, send email to datamapper@googlegroups.com.
 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 datamapper+unsubscr...@googlegroups.com.
To post to this group, send email to datamapper@googlegroups.com.
Visit this group at http://groups.google.com/group/datamapper?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [DataMapper] Override Accessor To Hide Caching

2013-02-08 Thread Neil C
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 
 ne...@vidyasource.comjavascript: 
 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 datamapper+...@googlegroups.com javascript:.
 To post to this group, send email to datam...@googlegroups.comjavascript:
 .
 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 datamapper+unsubscr...@googlegroups.com.
To post to this group, send email to datamapper@googlegroups.com.
Visit this group at http://groups.google.com/group/datamapper?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.