Prev | Current Page 177 | Next

Brad Ediger

"Advanced Rails"

A sample instance of acts_as_cached might look like this:
class Client < ActiveRecord::Base
acts_as_cached
# We have to expire the cache ourselves upon significant changes
after_save :expire_me
after_destroy :expire_me
protected
* Pronounced ???mem-cache-dee,??? for ???memory cache daemon.??? Available from http://danga.com/memcached/.
120 | Chapter 4: Database
def expire_me
expire_cache(id)
end
end
Of course, the proper solution for you will depend on the specific needs of the application.
Keep in mind that any caching is primarily about optimization, and the old
warnings against premature optimization always apply. Optimization should always
be targeted at a specific, measured performance problem. Without specificity, you
don??™t know what metric you are (or should be) measuring. Without measurement,
you don??™t know when or by how much you??™ve improved it.
Load Balancing and High Availability
Many applications require some form of load balancing and/or high availability.
Though these terms are often used together and they can often be obtained by the
same methods, they are fundamentally two different requirements. We define them
thus:
Load balancing
Spreading request load over several systems so as to reduce the load placed on a
single system.
High availability
Resiliency to the failure of one or several constituent components; the ability to
continue providing services without interruption despite component failure.


Pages:
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189