Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract_and_cache :attribute, :from => referenced_object (delegation with cache) #70

Open
thhermansen opened this issue Oct 4, 2011 · 0 comments

Comments

@thhermansen
Copy link
Contributor

Multiple models in Companybook's Rails application caches some attributes from referenced records. For instance, let's say you have a person which has one car and multiple addresses. We want to be able to read the car's color to present in the view without actually loading the car. We could have something like:

class Person < MassiveRecord::ORM::Table
  references_many :addresses
  references_one :car

  #
  # This generates reader methods like person.car_color, which reads from a cache,
  # not loading up the actual car object to read color from it.
  #
  extract_and_cache :color, :from => :car

  #
  # Since addresses is representing a collection this would iterate over
  # all addresses-records on save and collect zip codes and cache them
  # so when you call person.addresses_zip_codes you'll accessing that
  # cached array.
  #
  extract_and_cache :zip_codes, :postal_areas, :from => :addresses
end

So, this will result in setting up some save-hooks to serialize the cache data. Also setting up some read methods to read from the cache. Good idea? Need to check if it exists a gem for delegation with cache already, even though it should not be a huge job to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant