Well, you can just cache the User IDs and then exclude these IDs in your finder conditions. In your example, assuming you have a friends array of hashes containing ids and names.
Up vote 0 down vote favorite 1 share g+ share fb share tw.
For instance, I usually get a list of non-friends with this: non_friends = User. All - current_user. Friends Here, current_user.
Friends would be replaced by the cached array, only with the cached attributes: friends = #, #, … Is it possible? Is it a good approach to caching? (a big list of ActiveRecords doesn't fit into a 1MB Memcache chunk.
) Thank you, Kevin edit: The idea behind this is to use a sorted/processed list of 2000 ActiveRecords around which my app heavily uses, but since it doesn't fit into a Memcache chunk, I'm trying to cache the interesting attributes only as an array. Now, how can I use this array like it was an ActiveRecord array? Ruby-on-rails ruby activerecord memcached link|improve this question edited Oct 22 '10 at 14:18 asked Oct 22 '10 at 13:49Kevin13511 73% accept rate.
– Lichtamberg Oct 22 '10 at 13:54 Ruby array methods, like "&" or "-" are very useful, but I can't compare an ActiveRecord array like User. All and an hash array like {:id => 1, :name => "Kevin"}, … – Kevin Oct 22 '10 at 14:12 User.all. To_a - User.
Find(:all, :active => true). To_a works? :D And I don't get it.. Rails AR Collections have most of the array methods?
– Lichtamberg Oct 22 '10 at 14:29 The problem is, User. All can't be cached. I want to replace User.
All with something that can fit in cache, like a lighter array, but still be able to compare it with an array of ActiveRecords. In other words: how to build an ActiveRecords array (the second 'friends' array) from a hash array (the first 'friends' array)? – Kevin Oct 22 '10 at 14:38.
Well, you can just cache the User IDs and then exclude these IDs in your finder conditions. In your example, assuming you have a friends array of hashes containing ids and names: friend_ids = friends. Map{ |f| f:id } if friend_ids.
Empty? Non_friends = User. All else non_friends = User.
All(:conditions => 'id NOT IN (?)', current_user. Friend_ids) end.
I still have to query the database, but you are right, for less users than without the cache. I'll try this. Thanks :-) – Kevin Oct 22 '10 at 16:19.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.