Upload
ken-collins
View
1.521
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
MemcachedKen Collins ltmetaskillsnetgt
757rb ndash July 14th 2009
About Memcached
Stands For Memory Cache Daemon
By Brad Fitzgerald founder of LiveJournal
Introduced in October of 2003 to keep frequently-used LiveJournal objects in memory Including logins colors styles journal entries commets site text etc
Used by many major sites including Flickr Slashdot Wikipedia and Facebook
What Is Memcached (Or Not)
A server(s) that caches Name Value Pairs (NVPs) in memory This could be
NOT a persistent data store
NOT queryable for a list of all objects Only way to find something is to ask for it by name (by design)
No built-in security mechanisms
No fail-overhigh-availability mechanisms (server goes down data is gone)
Memcached Layout
Basically Client lt=gt (NVP)Server
Server simple fast data retrival based on a key
Size of key can not exceed 250 characters
Size of value can not exceed 1 MB
Each memcached server is atomic Neither knows or cares about any other memcached server
Client libraries for most every major language We will focus on the Ruby client used by Rails
Installation amp Configuration
Mac OS $ sudo port install memcached
Others pretty easy Only dependency is libevent(see httpdangacommemcached)
Key arguments are -p -m and -d All using -h
LaunchDaemon $ memcached -u nobody -m 512 -c 1024 -p 11211 -d
Styling amp Profiling ) Memcachedalias mcconf=mate optlocaletcLaunchDaemonsorgmacportsmemcachedmemcachedwrapperalias stopmc=sudo launchctl stop orgmacportsmemcachedalias startmc=sudo launchctl start orgmacportsmemcachedalias mcr=stopmc startmc
Memcached Basic CommandsADD Only store data if the key does NOT exist
REPLACE Only store data if the key ALREADY exists
SET Add or replace data
GET Return data
INCR Increment a counter
DECR Decrement a counter
Rails With MemcachedSessions (configinitializerssession_storerb)ActionControllerBasesession_store = mem_cache_store lsquolocalhostrsquo
Everywhere Else ActiveSupportCache (configinitializersenvironmentsrb)configaction_controllerperform_caching = trueconfigcache_store = mem_cache_store
ActiveSupportCache ImplementationsFileStore
MemoryStore
SynchronizedMemoryStore
DRbStore
MemCacheStore
CompressedMemCacheStore
Accessible as Railscache
ActiveSupportCache Details
All implementations inherit from ActiveSupportCacheStore which define a common simple interface
read(key options = nil)write(key value options = nil)fetch(key options = )delete(key options = nil)delete_matched(matcher options = nil)exist(key options = nil)increment(key amount = 1)decrement(key amount = 1)
read(keyoptions=nil)cacheread(ids) =gt nilcachewrite(ids[123]) =gt truecacheread(ids) =gt [1 2 3]cacheread(ids raw =gt true) =gt 004b[bi006iaib
write(keyvalueoptions=nil)cachewrite(foo bar expires_in =gt 5seconds)cacheread(foo) =gt barsleep(6)cacheread(foo) =gt nil
fetch(keyoptions=)cachewrite(today Tuesday)cachefetch(today) =gt Tuesday
cachefetch(city) =gt nilcachefetch(city) do Duckburghendcachefetch(city) =gt Duckburgh
cachewrite(today Tuesday)cachefetch(today force =gt true) =gt nil
cache = ActiveSupportCacheMemCacheStorenewcachefetch(foo force =gt true expires_in =gt 5seconds) do barendcachefetch(foo) =gt barsleep(6)cachefetch(foo) =gt nil
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
About Memcached
Stands For Memory Cache Daemon
By Brad Fitzgerald founder of LiveJournal
Introduced in October of 2003 to keep frequently-used LiveJournal objects in memory Including logins colors styles journal entries commets site text etc
Used by many major sites including Flickr Slashdot Wikipedia and Facebook
What Is Memcached (Or Not)
A server(s) that caches Name Value Pairs (NVPs) in memory This could be
NOT a persistent data store
NOT queryable for a list of all objects Only way to find something is to ask for it by name (by design)
No built-in security mechanisms
No fail-overhigh-availability mechanisms (server goes down data is gone)
Memcached Layout
Basically Client lt=gt (NVP)Server
Server simple fast data retrival based on a key
Size of key can not exceed 250 characters
Size of value can not exceed 1 MB
Each memcached server is atomic Neither knows or cares about any other memcached server
Client libraries for most every major language We will focus on the Ruby client used by Rails
Installation amp Configuration
Mac OS $ sudo port install memcached
Others pretty easy Only dependency is libevent(see httpdangacommemcached)
Key arguments are -p -m and -d All using -h
LaunchDaemon $ memcached -u nobody -m 512 -c 1024 -p 11211 -d
Styling amp Profiling ) Memcachedalias mcconf=mate optlocaletcLaunchDaemonsorgmacportsmemcachedmemcachedwrapperalias stopmc=sudo launchctl stop orgmacportsmemcachedalias startmc=sudo launchctl start orgmacportsmemcachedalias mcr=stopmc startmc
Memcached Basic CommandsADD Only store data if the key does NOT exist
REPLACE Only store data if the key ALREADY exists
SET Add or replace data
GET Return data
INCR Increment a counter
DECR Decrement a counter
Rails With MemcachedSessions (configinitializerssession_storerb)ActionControllerBasesession_store = mem_cache_store lsquolocalhostrsquo
Everywhere Else ActiveSupportCache (configinitializersenvironmentsrb)configaction_controllerperform_caching = trueconfigcache_store = mem_cache_store
ActiveSupportCache ImplementationsFileStore
MemoryStore
SynchronizedMemoryStore
DRbStore
MemCacheStore
CompressedMemCacheStore
Accessible as Railscache
ActiveSupportCache Details
All implementations inherit from ActiveSupportCacheStore which define a common simple interface
read(key options = nil)write(key value options = nil)fetch(key options = )delete(key options = nil)delete_matched(matcher options = nil)exist(key options = nil)increment(key amount = 1)decrement(key amount = 1)
read(keyoptions=nil)cacheread(ids) =gt nilcachewrite(ids[123]) =gt truecacheread(ids) =gt [1 2 3]cacheread(ids raw =gt true) =gt 004b[bi006iaib
write(keyvalueoptions=nil)cachewrite(foo bar expires_in =gt 5seconds)cacheread(foo) =gt barsleep(6)cacheread(foo) =gt nil
fetch(keyoptions=)cachewrite(today Tuesday)cachefetch(today) =gt Tuesday
cachefetch(city) =gt nilcachefetch(city) do Duckburghendcachefetch(city) =gt Duckburgh
cachewrite(today Tuesday)cachefetch(today force =gt true) =gt nil
cache = ActiveSupportCacheMemCacheStorenewcachefetch(foo force =gt true expires_in =gt 5seconds) do barendcachefetch(foo) =gt barsleep(6)cachefetch(foo) =gt nil
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
What Is Memcached (Or Not)
A server(s) that caches Name Value Pairs (NVPs) in memory This could be
NOT a persistent data store
NOT queryable for a list of all objects Only way to find something is to ask for it by name (by design)
No built-in security mechanisms
No fail-overhigh-availability mechanisms (server goes down data is gone)
Memcached Layout
Basically Client lt=gt (NVP)Server
Server simple fast data retrival based on a key
Size of key can not exceed 250 characters
Size of value can not exceed 1 MB
Each memcached server is atomic Neither knows or cares about any other memcached server
Client libraries for most every major language We will focus on the Ruby client used by Rails
Installation amp Configuration
Mac OS $ sudo port install memcached
Others pretty easy Only dependency is libevent(see httpdangacommemcached)
Key arguments are -p -m and -d All using -h
LaunchDaemon $ memcached -u nobody -m 512 -c 1024 -p 11211 -d
Styling amp Profiling ) Memcachedalias mcconf=mate optlocaletcLaunchDaemonsorgmacportsmemcachedmemcachedwrapperalias stopmc=sudo launchctl stop orgmacportsmemcachedalias startmc=sudo launchctl start orgmacportsmemcachedalias mcr=stopmc startmc
Memcached Basic CommandsADD Only store data if the key does NOT exist
REPLACE Only store data if the key ALREADY exists
SET Add or replace data
GET Return data
INCR Increment a counter
DECR Decrement a counter
Rails With MemcachedSessions (configinitializerssession_storerb)ActionControllerBasesession_store = mem_cache_store lsquolocalhostrsquo
Everywhere Else ActiveSupportCache (configinitializersenvironmentsrb)configaction_controllerperform_caching = trueconfigcache_store = mem_cache_store
ActiveSupportCache ImplementationsFileStore
MemoryStore
SynchronizedMemoryStore
DRbStore
MemCacheStore
CompressedMemCacheStore
Accessible as Railscache
ActiveSupportCache Details
All implementations inherit from ActiveSupportCacheStore which define a common simple interface
read(key options = nil)write(key value options = nil)fetch(key options = )delete(key options = nil)delete_matched(matcher options = nil)exist(key options = nil)increment(key amount = 1)decrement(key amount = 1)
read(keyoptions=nil)cacheread(ids) =gt nilcachewrite(ids[123]) =gt truecacheread(ids) =gt [1 2 3]cacheread(ids raw =gt true) =gt 004b[bi006iaib
write(keyvalueoptions=nil)cachewrite(foo bar expires_in =gt 5seconds)cacheread(foo) =gt barsleep(6)cacheread(foo) =gt nil
fetch(keyoptions=)cachewrite(today Tuesday)cachefetch(today) =gt Tuesday
cachefetch(city) =gt nilcachefetch(city) do Duckburghendcachefetch(city) =gt Duckburgh
cachewrite(today Tuesday)cachefetch(today force =gt true) =gt nil
cache = ActiveSupportCacheMemCacheStorenewcachefetch(foo force =gt true expires_in =gt 5seconds) do barendcachefetch(foo) =gt barsleep(6)cachefetch(foo) =gt nil
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
Memcached Layout
Basically Client lt=gt (NVP)Server
Server simple fast data retrival based on a key
Size of key can not exceed 250 characters
Size of value can not exceed 1 MB
Each memcached server is atomic Neither knows or cares about any other memcached server
Client libraries for most every major language We will focus on the Ruby client used by Rails
Installation amp Configuration
Mac OS $ sudo port install memcached
Others pretty easy Only dependency is libevent(see httpdangacommemcached)
Key arguments are -p -m and -d All using -h
LaunchDaemon $ memcached -u nobody -m 512 -c 1024 -p 11211 -d
Styling amp Profiling ) Memcachedalias mcconf=mate optlocaletcLaunchDaemonsorgmacportsmemcachedmemcachedwrapperalias stopmc=sudo launchctl stop orgmacportsmemcachedalias startmc=sudo launchctl start orgmacportsmemcachedalias mcr=stopmc startmc
Memcached Basic CommandsADD Only store data if the key does NOT exist
REPLACE Only store data if the key ALREADY exists
SET Add or replace data
GET Return data
INCR Increment a counter
DECR Decrement a counter
Rails With MemcachedSessions (configinitializerssession_storerb)ActionControllerBasesession_store = mem_cache_store lsquolocalhostrsquo
Everywhere Else ActiveSupportCache (configinitializersenvironmentsrb)configaction_controllerperform_caching = trueconfigcache_store = mem_cache_store
ActiveSupportCache ImplementationsFileStore
MemoryStore
SynchronizedMemoryStore
DRbStore
MemCacheStore
CompressedMemCacheStore
Accessible as Railscache
ActiveSupportCache Details
All implementations inherit from ActiveSupportCacheStore which define a common simple interface
read(key options = nil)write(key value options = nil)fetch(key options = )delete(key options = nil)delete_matched(matcher options = nil)exist(key options = nil)increment(key amount = 1)decrement(key amount = 1)
read(keyoptions=nil)cacheread(ids) =gt nilcachewrite(ids[123]) =gt truecacheread(ids) =gt [1 2 3]cacheread(ids raw =gt true) =gt 004b[bi006iaib
write(keyvalueoptions=nil)cachewrite(foo bar expires_in =gt 5seconds)cacheread(foo) =gt barsleep(6)cacheread(foo) =gt nil
fetch(keyoptions=)cachewrite(today Tuesday)cachefetch(today) =gt Tuesday
cachefetch(city) =gt nilcachefetch(city) do Duckburghendcachefetch(city) =gt Duckburgh
cachewrite(today Tuesday)cachefetch(today force =gt true) =gt nil
cache = ActiveSupportCacheMemCacheStorenewcachefetch(foo force =gt true expires_in =gt 5seconds) do barendcachefetch(foo) =gt barsleep(6)cachefetch(foo) =gt nil
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
Installation amp Configuration
Mac OS $ sudo port install memcached
Others pretty easy Only dependency is libevent(see httpdangacommemcached)
Key arguments are -p -m and -d All using -h
LaunchDaemon $ memcached -u nobody -m 512 -c 1024 -p 11211 -d
Styling amp Profiling ) Memcachedalias mcconf=mate optlocaletcLaunchDaemonsorgmacportsmemcachedmemcachedwrapperalias stopmc=sudo launchctl stop orgmacportsmemcachedalias startmc=sudo launchctl start orgmacportsmemcachedalias mcr=stopmc startmc
Memcached Basic CommandsADD Only store data if the key does NOT exist
REPLACE Only store data if the key ALREADY exists
SET Add or replace data
GET Return data
INCR Increment a counter
DECR Decrement a counter
Rails With MemcachedSessions (configinitializerssession_storerb)ActionControllerBasesession_store = mem_cache_store lsquolocalhostrsquo
Everywhere Else ActiveSupportCache (configinitializersenvironmentsrb)configaction_controllerperform_caching = trueconfigcache_store = mem_cache_store
ActiveSupportCache ImplementationsFileStore
MemoryStore
SynchronizedMemoryStore
DRbStore
MemCacheStore
CompressedMemCacheStore
Accessible as Railscache
ActiveSupportCache Details
All implementations inherit from ActiveSupportCacheStore which define a common simple interface
read(key options = nil)write(key value options = nil)fetch(key options = )delete(key options = nil)delete_matched(matcher options = nil)exist(key options = nil)increment(key amount = 1)decrement(key amount = 1)
read(keyoptions=nil)cacheread(ids) =gt nilcachewrite(ids[123]) =gt truecacheread(ids) =gt [1 2 3]cacheread(ids raw =gt true) =gt 004b[bi006iaib
write(keyvalueoptions=nil)cachewrite(foo bar expires_in =gt 5seconds)cacheread(foo) =gt barsleep(6)cacheread(foo) =gt nil
fetch(keyoptions=)cachewrite(today Tuesday)cachefetch(today) =gt Tuesday
cachefetch(city) =gt nilcachefetch(city) do Duckburghendcachefetch(city) =gt Duckburgh
cachewrite(today Tuesday)cachefetch(today force =gt true) =gt nil
cache = ActiveSupportCacheMemCacheStorenewcachefetch(foo force =gt true expires_in =gt 5seconds) do barendcachefetch(foo) =gt barsleep(6)cachefetch(foo) =gt nil
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
Styling amp Profiling ) Memcachedalias mcconf=mate optlocaletcLaunchDaemonsorgmacportsmemcachedmemcachedwrapperalias stopmc=sudo launchctl stop orgmacportsmemcachedalias startmc=sudo launchctl start orgmacportsmemcachedalias mcr=stopmc startmc
Memcached Basic CommandsADD Only store data if the key does NOT exist
REPLACE Only store data if the key ALREADY exists
SET Add or replace data
GET Return data
INCR Increment a counter
DECR Decrement a counter
Rails With MemcachedSessions (configinitializerssession_storerb)ActionControllerBasesession_store = mem_cache_store lsquolocalhostrsquo
Everywhere Else ActiveSupportCache (configinitializersenvironmentsrb)configaction_controllerperform_caching = trueconfigcache_store = mem_cache_store
ActiveSupportCache ImplementationsFileStore
MemoryStore
SynchronizedMemoryStore
DRbStore
MemCacheStore
CompressedMemCacheStore
Accessible as Railscache
ActiveSupportCache Details
All implementations inherit from ActiveSupportCacheStore which define a common simple interface
read(key options = nil)write(key value options = nil)fetch(key options = )delete(key options = nil)delete_matched(matcher options = nil)exist(key options = nil)increment(key amount = 1)decrement(key amount = 1)
read(keyoptions=nil)cacheread(ids) =gt nilcachewrite(ids[123]) =gt truecacheread(ids) =gt [1 2 3]cacheread(ids raw =gt true) =gt 004b[bi006iaib
write(keyvalueoptions=nil)cachewrite(foo bar expires_in =gt 5seconds)cacheread(foo) =gt barsleep(6)cacheread(foo) =gt nil
fetch(keyoptions=)cachewrite(today Tuesday)cachefetch(today) =gt Tuesday
cachefetch(city) =gt nilcachefetch(city) do Duckburghendcachefetch(city) =gt Duckburgh
cachewrite(today Tuesday)cachefetch(today force =gt true) =gt nil
cache = ActiveSupportCacheMemCacheStorenewcachefetch(foo force =gt true expires_in =gt 5seconds) do barendcachefetch(foo) =gt barsleep(6)cachefetch(foo) =gt nil
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
Memcached Basic CommandsADD Only store data if the key does NOT exist
REPLACE Only store data if the key ALREADY exists
SET Add or replace data
GET Return data
INCR Increment a counter
DECR Decrement a counter
Rails With MemcachedSessions (configinitializerssession_storerb)ActionControllerBasesession_store = mem_cache_store lsquolocalhostrsquo
Everywhere Else ActiveSupportCache (configinitializersenvironmentsrb)configaction_controllerperform_caching = trueconfigcache_store = mem_cache_store
ActiveSupportCache ImplementationsFileStore
MemoryStore
SynchronizedMemoryStore
DRbStore
MemCacheStore
CompressedMemCacheStore
Accessible as Railscache
ActiveSupportCache Details
All implementations inherit from ActiveSupportCacheStore which define a common simple interface
read(key options = nil)write(key value options = nil)fetch(key options = )delete(key options = nil)delete_matched(matcher options = nil)exist(key options = nil)increment(key amount = 1)decrement(key amount = 1)
read(keyoptions=nil)cacheread(ids) =gt nilcachewrite(ids[123]) =gt truecacheread(ids) =gt [1 2 3]cacheread(ids raw =gt true) =gt 004b[bi006iaib
write(keyvalueoptions=nil)cachewrite(foo bar expires_in =gt 5seconds)cacheread(foo) =gt barsleep(6)cacheread(foo) =gt nil
fetch(keyoptions=)cachewrite(today Tuesday)cachefetch(today) =gt Tuesday
cachefetch(city) =gt nilcachefetch(city) do Duckburghendcachefetch(city) =gt Duckburgh
cachewrite(today Tuesday)cachefetch(today force =gt true) =gt nil
cache = ActiveSupportCacheMemCacheStorenewcachefetch(foo force =gt true expires_in =gt 5seconds) do barendcachefetch(foo) =gt barsleep(6)cachefetch(foo) =gt nil
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
Rails With MemcachedSessions (configinitializerssession_storerb)ActionControllerBasesession_store = mem_cache_store lsquolocalhostrsquo
Everywhere Else ActiveSupportCache (configinitializersenvironmentsrb)configaction_controllerperform_caching = trueconfigcache_store = mem_cache_store
ActiveSupportCache ImplementationsFileStore
MemoryStore
SynchronizedMemoryStore
DRbStore
MemCacheStore
CompressedMemCacheStore
Accessible as Railscache
ActiveSupportCache Details
All implementations inherit from ActiveSupportCacheStore which define a common simple interface
read(key options = nil)write(key value options = nil)fetch(key options = )delete(key options = nil)delete_matched(matcher options = nil)exist(key options = nil)increment(key amount = 1)decrement(key amount = 1)
read(keyoptions=nil)cacheread(ids) =gt nilcachewrite(ids[123]) =gt truecacheread(ids) =gt [1 2 3]cacheread(ids raw =gt true) =gt 004b[bi006iaib
write(keyvalueoptions=nil)cachewrite(foo bar expires_in =gt 5seconds)cacheread(foo) =gt barsleep(6)cacheread(foo) =gt nil
fetch(keyoptions=)cachewrite(today Tuesday)cachefetch(today) =gt Tuesday
cachefetch(city) =gt nilcachefetch(city) do Duckburghendcachefetch(city) =gt Duckburgh
cachewrite(today Tuesday)cachefetch(today force =gt true) =gt nil
cache = ActiveSupportCacheMemCacheStorenewcachefetch(foo force =gt true expires_in =gt 5seconds) do barendcachefetch(foo) =gt barsleep(6)cachefetch(foo) =gt nil
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
ActiveSupportCache Details
All implementations inherit from ActiveSupportCacheStore which define a common simple interface
read(key options = nil)write(key value options = nil)fetch(key options = )delete(key options = nil)delete_matched(matcher options = nil)exist(key options = nil)increment(key amount = 1)decrement(key amount = 1)
read(keyoptions=nil)cacheread(ids) =gt nilcachewrite(ids[123]) =gt truecacheread(ids) =gt [1 2 3]cacheread(ids raw =gt true) =gt 004b[bi006iaib
write(keyvalueoptions=nil)cachewrite(foo bar expires_in =gt 5seconds)cacheread(foo) =gt barsleep(6)cacheread(foo) =gt nil
fetch(keyoptions=)cachewrite(today Tuesday)cachefetch(today) =gt Tuesday
cachefetch(city) =gt nilcachefetch(city) do Duckburghendcachefetch(city) =gt Duckburgh
cachewrite(today Tuesday)cachefetch(today force =gt true) =gt nil
cache = ActiveSupportCacheMemCacheStorenewcachefetch(foo force =gt true expires_in =gt 5seconds) do barendcachefetch(foo) =gt barsleep(6)cachefetch(foo) =gt nil
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
read(keyoptions=nil)cacheread(ids) =gt nilcachewrite(ids[123]) =gt truecacheread(ids) =gt [1 2 3]cacheread(ids raw =gt true) =gt 004b[bi006iaib
write(keyvalueoptions=nil)cachewrite(foo bar expires_in =gt 5seconds)cacheread(foo) =gt barsleep(6)cacheread(foo) =gt nil
fetch(keyoptions=)cachewrite(today Tuesday)cachefetch(today) =gt Tuesday
cachefetch(city) =gt nilcachefetch(city) do Duckburghendcachefetch(city) =gt Duckburgh
cachewrite(today Tuesday)cachefetch(today force =gt true) =gt nil
cache = ActiveSupportCacheMemCacheStorenewcachefetch(foo force =gt true expires_in =gt 5seconds) do barendcachefetch(foo) =gt barsleep(6)cachefetch(foo) =gt nil
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
fetch(keyoptions=)cachewrite(today Tuesday)cachefetch(today) =gt Tuesday
cachefetch(city) =gt nilcachefetch(city) do Duckburghendcachefetch(city) =gt Duckburgh
cachewrite(today Tuesday)cachefetch(today force =gt true) =gt nil
cache = ActiveSupportCacheMemCacheStorenewcachefetch(foo force =gt true expires_in =gt 5seconds) do barendcachefetch(foo) =gt barsleep(6)cachefetch(foo) =gt nil
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
delete(keyoptions=nil)cachewrite(ids[123]) =gt truecachedelete(ids) =gt truecacheread(ids) =gt nilcachedelete(notthere) =gt false
exist(keyoptions=nil) Doesnt call super cause exist in memcached is in fact a read But who cares Reading is very fast anywayread(key options)nil
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
increment(keyamount=1)decrement(keyamount=1)cacheread(key) =gt nilcacheincrement(key) =gt nilcachewrite(key20) =gt truecacheincrement(key) =gt 1cacheread(key) =gt nilcacheincrement(key) =gt 2cacheincrement(key) =gt 3cacheincrement(key) =gt 4cachedecrement(key) =gt 3cacheincrement(key7) =gt 10cachedecrement(key5) =gt 5
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
MemCacheStore Specificsclear ndash Performs a flush_all command on the memcached client Deletes all data
stats ndash Returns a server keyed hash built from each the memcached clientrsquos server connection
gtgt cachestats=gt localhost11211=gtget_hits=gt1518 bytes=gt212577 rusage_system=gt0890843 pid=gt18081 connection_structures=gt11 accepting_conns=gt1 threads=gt5 limit_maxbytes=gt536870912 evictions=gt0 cmd_flush=gt1 pointer_size=gt32 time=gt1247589002 version=gt128 listen_disabled_num=gt0 bytes_written=gt191926 total_items=gt2191 cmd_get=gt1883 total_connections=gt12 curr_connections=gt10 uptime=gt77901 cmd_set=gt2191 rusage_user=gt0438621 bytes_read=gt269582 get_misses=gt365 curr_items=gt1998
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
Going Deeper
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
Multiple ServersClient implements a get_server_for_key which determines a server hash and who gets the data
Lets make another server$ memcached -u nobody -m 512 -p 11212 -U 11212 -d
RailsInitializerrun do |config| configcache_store = [mem_cache_storelocalhost11211localhost11212]end
(11000)to_aeach |n| Railscachewrite(nto_ssomedata)
Railscachestatseach do |serverstats| puts TotalItems [server] stats[total_items]end
TotalItems [localhost11211] 446 TotalItems [localhost11212] 554
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
Client CompressionDone Thanks Rails Just use compressed_mem_cache_store
module ActiveSupport module Cache class CompressedMemCacheStore lt MemCacheStore def read(name options = nil) if value = super(name (options || )merge(raw =gt true)) if raw(options) value else Marshalload(ActiveSupportGzipdecompress(value)) end end end
def write(name value options = nil) value = ActiveSupportGzipcompress(Marshaldump(value)) unless raw(options) super(name value (options || )merge(raw =gt true)) end end endend
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
What To CacheBasic types like strings integers arrays or hashes The general rule is to consider the same objects that you might put in a session ignoring size
cachewrite myarray [123] =gt truea1 = cacheread(myarray) =gt [1 2 3]a2 = cacheread(myarray) =gt [1 2 3]a1object_id == a2object_id =gt falsecacheread(myarray) ltlt 4 =gt [1 2 3 4]cacheread(myarray) =gt [1 2 3]
class MyClass attr_accessor this thatend
mo = MyClassnew =gt ltMyClass0x26c7198gtmothis = [123] cachewrite myobject mo turemo1 = cacheread(myobject) =gt ltMyClass0x26ae6c0 this=[1 2 3]gtmo1this =gt [1 2 3]
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
Caching In Action
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
Review Nahum Wildrsquos Article on Spandex Memcached which is not part of Rails 23
httpwwwmotionstandingstillcomspandex-memcache-store-is-now-in-rails-232009-02-04
httpsrailslighthouseappcomprojects8994tickets1653-per-request-in-memory-cache-for-all-communication-with-the-memcache-servers
Review Nahum Wildrsquos Article on Starting Simple Rails Caching Lesson is start with small line items vs page
httpwwwmotionstandingstillcomstarting-simple-with-rails-caching2008-11-27
Demostrate The Above With ldquoplay_cacherdquo rails app Included in this keynote with screen highlights on next slide
Live Discussion Abstract
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
Demo App
lth1gtArticlesindexlth1gt
lttablegt lttrgt ltthgtIDltthgt ltthgtUserltthgt ltthgtTitleltthgt ltthgtCommentsltthgt ltthgtBodyltthgt lttrgt lt articleseach do |article| gt lttr class=lt= cycle(evenodd) gtgt lt cache([listarticle]) do gt lttd class=centergtlt= articleid gtlttdgt lttd class=center w50gtlt= articleusername gtlttdgt lttd class=center w150gtlt= articletitle gtlttdgt lttd class=centergtlt= articlecommentscount gtlttdgt lttdgtlt= truncate(articlebody length =gt 50) gtlttdgt lt end gt lttrgt lt end gtlttablegt
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources
GUI Version Of Memcached For Machttpgithubcomandrewfromcalimcinsighttreemaster
CacheMoney Rails Pluginhttpgithubcomnkallencache-moneytreemaster
Other Resources