SlideShare a Scribd company logo
Using Memcache to improve PHP performanceSudar Muthu (@sudarmuthu)http://sudarmuthu.comResearch EngineerYahoo ResearchBangalore PHP user group29-May-2010
AgendaOverviewMemcache PrinciplesHow Memcache worksGeneral UsageMemcache LimitsClient LibrariesCommon Use casesTips for optimizationUsing Memcache in WordPress
OverviewA high-performance Distributed Memory Object Caching SystemIntended for speeding up dynamic web applications by alleviating database load.Open source & distributed under a “permissive  free software licence”.Uses RAM for storage Acts as a dictionary of stored data with key /value pairs
Memcache PrinciplesIt is not a databaseIt does not provide redundancyIt doesn't handle failoverIt does not provide authenticationIt does not allow locksNo direct dump or backup possible
How Memcache worksTwo stage hash, like a giant hash table looking  up key=value pairsClient hashes the key against a list of servers When the server is identified, the client sends  its request Server performs a hash key lookup for the  actual data
General UsageFirst look up in memcache before querying the database.If present, return it.Else query the database, store it in memcache and return it.If the data changes, delete it from cache.
Memcache LimitsA single value cannot contain more than 1 MB of data.A single key cannot be more than 250 characters in length.Normally a single memcache instance cannot be more than 2 GB in size.
Client LibrariesPerl, Python, Ruby, Java, C#, CPostgreSQL (access memcached from procs and triggers)MySQL (adds memcache_engine storage engine)PHP (pecl/memcache)
Client Libraries – PHP APIKey MethodsboolMemcache::connect  ( string $host  [, int $port  [, int $timeout  ]] )
boolMemcache::set( string $key  , mixed $var  [, int $flag  [, int $expire  ]] )
string Memcache::get  ( string $key  [, int &$flags  ] )
boolMemcache::delete  ( string $key  [, int $timeout  ] )More: http://www.php.net/memcache
Common Use cases - 1Simple query result caching$key = ”some:unique:key";  if ($memcache‐>get($key)) {    		return $memcache‐>get($key);  }  else {    		// Run the query get the result data		$result = $db‐>query(“query”);     	$memcache‐>set($key, $result, TRUE, 300); 		// Store the result of the query for 5 minutes     	return $result;  } 
Common Use cases - 2Caching network/webservice calls$key = ”some:unique:key"; if ($memcache->get($key)) {   		return $memcache->get($key); } else {   		// Download the page    		$url = ”Your webserviceurl";	       $result = fetch($url);    		$memcache->set($key, $result, false, 86400); 		// Store the result of the query for a day    		return $result; }
Common Use cases - 3Throttle user activity $key = “some:unique:key”; if ($memcache->get($key)) {   	//Deny access   		return false; } else {    		$memcache->set($key, “1”, false, 60);    		//Allow access    		return true; }
Ad

Recommended

Memcache
Memcache
Abhinav Singh
 
Memcached Presentation
Memcached Presentation
Asif Ali
 
Cassandra as Memcache
Cassandra as Memcache
Edward Capriolo
 
Memcache basics on google app engine
Memcache basics on google app engine
Ido Green
 
Memcached
Memcached
Shrawan Kumar Nirala
 
Memcached Study
Memcached Study
nam kwangjin
 
Memcached: What is it and what does it do?
Memcached: What is it and what does it do?
Brian Moon
 
Memcached: What is it and what does it do? (PHP Version)
Memcached: What is it and what does it do? (PHP Version)
Brian Moon
 
Introduction to memcached
Introduction to memcached
Jurriaan Persyn
 
캐시 분산처리 인프라
캐시 분산처리 인프라
Park Chunduck
 
Memcached Code Camp 2009
Memcached Code Camp 2009
NorthScale
 
Caching
Caching
Nascenia IT
 
Moxi - Memcached Proxy
Moxi - Memcached Proxy
NorthScale
 
Caching with Memcached and APC
Caching with Memcached and APC
Ben Ramsey
 
Speeding Up The Snail
Speeding Up The Snail
Marcus Deglos
 
Memcached B box presentation
Memcached B box presentation
Nagesh Chinkeri
 
Caching basics in PHP
Caching basics in PHP
Anis Ahmad
 
cache concepts and varnish-cache
cache concepts and varnish-cache
Marc Cortinas Val
 
Performance all teh things
Performance all teh things
Marcus Deglos
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
Wim Godden
 
04 web optimization
04 web optimization
Nguyen Duc Phu
 
Building low latency java applications with ehcache
Building low latency java applications with ehcache
Chris Westin
 
Scaling symfony apps
Scaling symfony apps
Matteo Moretti
 
Caching with Varnish
Caching with Varnish
schoefmax
 
Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Blaze Software Inc.
 
Caching Strategies
Caching Strategies
Michal Špaček
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalability
Wim Godden
 
Scalling web applications using memcache
Scalling web applications using memcache
Sudar Muthu
 
Caching for Cash: Caching
Caching for Cash: Caching
Scott MacVicar
 

More Related Content

What's hot (20)

Introduction to memcached
Introduction to memcached
Jurriaan Persyn
 
캐시 분산처리 인프라
캐시 분산처리 인프라
Park Chunduck
 
Memcached Code Camp 2009
Memcached Code Camp 2009
NorthScale
 
Caching
Caching
Nascenia IT
 
Moxi - Memcached Proxy
Moxi - Memcached Proxy
NorthScale
 
Caching with Memcached and APC
Caching with Memcached and APC
Ben Ramsey
 
Speeding Up The Snail
Speeding Up The Snail
Marcus Deglos
 
Memcached B box presentation
Memcached B box presentation
Nagesh Chinkeri
 
Caching basics in PHP
Caching basics in PHP
Anis Ahmad
 
cache concepts and varnish-cache
cache concepts and varnish-cache
Marc Cortinas Val
 
Performance all teh things
Performance all teh things
Marcus Deglos
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
Wim Godden
 
04 web optimization
04 web optimization
Nguyen Duc Phu
 
Building low latency java applications with ehcache
Building low latency java applications with ehcache
Chris Westin
 
Scaling symfony apps
Scaling symfony apps
Matteo Moretti
 
Caching with Varnish
Caching with Varnish
schoefmax
 
Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Blaze Software Inc.
 
Caching Strategies
Caching Strategies
Michal Špaček
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalability
Wim Godden
 
Introduction to memcached
Introduction to memcached
Jurriaan Persyn
 
캐시 분산처리 인프라
캐시 분산처리 인프라
Park Chunduck
 
Memcached Code Camp 2009
Memcached Code Camp 2009
NorthScale
 
Moxi - Memcached Proxy
Moxi - Memcached Proxy
NorthScale
 
Caching with Memcached and APC
Caching with Memcached and APC
Ben Ramsey
 
Speeding Up The Snail
Speeding Up The Snail
Marcus Deglos
 
Memcached B box presentation
Memcached B box presentation
Nagesh Chinkeri
 
Caching basics in PHP
Caching basics in PHP
Anis Ahmad
 
cache concepts and varnish-cache
cache concepts and varnish-cache
Marc Cortinas Val
 
Performance all teh things
Performance all teh things
Marcus Deglos
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
Wim Godden
 
Building low latency java applications with ehcache
Building low latency java applications with ehcache
Chris Westin
 
Caching with Varnish
Caching with Varnish
schoefmax
 
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Blaze Software Inc.
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalability
Wim Godden
 

Similar to Using memcache to improve php performance (20)

Scalling web applications using memcache
Scalling web applications using memcache
Sudar Muthu
 
Caching for Cash: Caching
Caching for Cash: Caching
Scott MacVicar
 
Give Your Site a Boost with Memcache
Give Your Site a Boost with Memcache
Ben Ramsey
 
1
1
tristup
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalability
Wim Godden
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
Wim Godden
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
Wim Godden
 
Caching Data For Performance
Caching Data For Performance
Dave Ross
 
Memcache d
Memcache d
Abhishek Tomar
 
Caching objects-in-memory
Caching objects-in-memory
Mauro Cassani
 
Memcache - Lightning fast object retrieval
Memcache - Lightning fast object retrieval
elliando dias
 
Memcache and Drupal - Vaibhav Jain
Memcache and Drupal - Vaibhav Jain
Drupal Camp Delhi
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalability
Wim Godden
 
APC & Memcache the High Performance Duo
APC & Memcache the High Performance Duo
Anis Berejeb
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
Achieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
Achieve Internet
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012
Wim Godden
 
Mysql wp memcached
Mysql wp memcached
kbour23
 
Dutch php conference_apc_mem2010
Dutch php conference_apc_mem2010
isnull
 
Barcelona apc mem2010
Barcelona apc mem2010
isnull
 
Scalling web applications using memcache
Scalling web applications using memcache
Sudar Muthu
 
Caching for Cash: Caching
Caching for Cash: Caching
Scott MacVicar
 
Give Your Site a Boost with Memcache
Give Your Site a Boost with Memcache
Ben Ramsey
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalability
Wim Godden
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
Wim Godden
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
Wim Godden
 
Caching Data For Performance
Caching Data For Performance
Dave Ross
 
Caching objects-in-memory
Caching objects-in-memory
Mauro Cassani
 
Memcache - Lightning fast object retrieval
Memcache - Lightning fast object retrieval
elliando dias
 
Memcache and Drupal - Vaibhav Jain
Memcache and Drupal - Vaibhav Jain
Drupal Camp Delhi
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalability
Wim Godden
 
APC & Memcache the High Performance Duo
APC & Memcache the High Performance Duo
Anis Berejeb
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
Achieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
Achieve Internet
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012
Wim Godden
 
Mysql wp memcached
Mysql wp memcached
kbour23
 
Dutch php conference_apc_mem2010
Dutch php conference_apc_mem2010
isnull
 
Barcelona apc mem2010
Barcelona apc mem2010
isnull
 
Ad

More from Sudar Muthu (20)

A quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress Meetup
Sudar Muthu
 
WordPress Developer tools
WordPress Developer tools
Sudar Muthu
 
WordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivity
Sudar Muthu
 
Unit testing for WordPress
Unit testing for WordPress
Sudar Muthu
 
Unit testing in php
Unit testing in php
Sudar Muthu
 
Using arduino and raspberry pi for internet of things
Using arduino and raspberry pi for internet of things
Sudar Muthu
 
How arduino helped me in life
How arduino helped me in life
Sudar Muthu
 
Having fun with hardware
Having fun with hardware
Sudar Muthu
 
Getting started with arduino workshop
Getting started with arduino workshop
Sudar Muthu
 
Python in raspberry pi
Python in raspberry pi
Sudar Muthu
 
Hack 101 at IIT Kanpur
Hack 101 at IIT Kanpur
Sudar Muthu
 
PureCSS open hack 2013
PureCSS open hack 2013
Sudar Muthu
 
Pig workshop
Pig workshop
Sudar Muthu
 
Arduino Robotics workshop day2
Arduino Robotics workshop day2
Sudar Muthu
 
Arduino Robotics workshop Day1
Arduino Robotics workshop Day1
Sudar Muthu
 
Hands on Hadoop and pig
Hands on Hadoop and pig
Sudar Muthu
 
Lets make robots
Lets make robots
Sudar Muthu
 
Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)
Sudar Muthu
 
Controlling robots using javascript
Controlling robots using javascript
Sudar Muthu
 
Picture perfect hacks with flickr API
Picture perfect hacks with flickr API
Sudar Muthu
 
A quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress Meetup
Sudar Muthu
 
WordPress Developer tools
WordPress Developer tools
Sudar Muthu
 
WordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivity
Sudar Muthu
 
Unit testing for WordPress
Unit testing for WordPress
Sudar Muthu
 
Unit testing in php
Unit testing in php
Sudar Muthu
 
Using arduino and raspberry pi for internet of things
Using arduino and raspberry pi for internet of things
Sudar Muthu
 
How arduino helped me in life
How arduino helped me in life
Sudar Muthu
 
Having fun with hardware
Having fun with hardware
Sudar Muthu
 
Getting started with arduino workshop
Getting started with arduino workshop
Sudar Muthu
 
Python in raspberry pi
Python in raspberry pi
Sudar Muthu
 
Hack 101 at IIT Kanpur
Hack 101 at IIT Kanpur
Sudar Muthu
 
PureCSS open hack 2013
PureCSS open hack 2013
Sudar Muthu
 
Arduino Robotics workshop day2
Arduino Robotics workshop day2
Sudar Muthu
 
Arduino Robotics workshop Day1
Arduino Robotics workshop Day1
Sudar Muthu
 
Hands on Hadoop and pig
Hands on Hadoop and pig
Sudar Muthu
 
Lets make robots
Lets make robots
Sudar Muthu
 
Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)
Sudar Muthu
 
Controlling robots using javascript
Controlling robots using javascript
Sudar Muthu
 
Picture perfect hacks with flickr API
Picture perfect hacks with flickr API
Sudar Muthu
 
Ad

Recently uploaded (20)

cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 

Using memcache to improve php performance

  • 1. Using Memcache to improve PHP performanceSudar Muthu (@sudarmuthu)http://sudarmuthu.comResearch EngineerYahoo ResearchBangalore PHP user group29-May-2010
  • 2. AgendaOverviewMemcache PrinciplesHow Memcache worksGeneral UsageMemcache LimitsClient LibrariesCommon Use casesTips for optimizationUsing Memcache in WordPress
  • 3. OverviewA high-performance Distributed Memory Object Caching SystemIntended for speeding up dynamic web applications by alleviating database load.Open source & distributed under a “permissive free software licence”.Uses RAM for storage Acts as a dictionary of stored data with key /value pairs
  • 4. Memcache PrinciplesIt is not a databaseIt does not provide redundancyIt doesn't handle failoverIt does not provide authenticationIt does not allow locksNo direct dump or backup possible
  • 5. How Memcache worksTwo stage hash, like a giant hash table looking up key=value pairsClient hashes the key against a list of servers When the server is identified, the client sends its request Server performs a hash key lookup for the actual data
  • 6. General UsageFirst look up in memcache before querying the database.If present, return it.Else query the database, store it in memcache and return it.If the data changes, delete it from cache.
  • 7. Memcache LimitsA single value cannot contain more than 1 MB of data.A single key cannot be more than 250 characters in length.Normally a single memcache instance cannot be more than 2 GB in size.
  • 8. Client LibrariesPerl, Python, Ruby, Java, C#, CPostgreSQL (access memcached from procs and triggers)MySQL (adds memcache_engine storage engine)PHP (pecl/memcache)
  • 9. Client Libraries – PHP APIKey MethodsboolMemcache::connect ( string $host [, int $port [, int $timeout ]] )
  • 10. boolMemcache::set( string $key , mixed $var [, int $flag [, int $expire ]] )
  • 11. string Memcache::get ( string $key [, int &$flags ] )
  • 12. boolMemcache::delete ( string $key [, int $timeout ] )More: http://www.php.net/memcache
  • 13. Common Use cases - 1Simple query result caching$key = ”some:unique:key";  if ($memcache‐>get($key)) {     return $memcache‐>get($key);  }  else {     // Run the query get the result data $result = $db‐>query(“query”);      $memcache‐>set($key, $result, TRUE, 300);  // Store the result of the query for 5 minutes      return $result;  } 
  • 14. Common Use cases - 2Caching network/webservice calls$key = ”some:unique:key"; if ($memcache->get($key)) { return $memcache->get($key); } else { // Download the page $url = ”Your webserviceurl"; $result = fetch($url); $memcache->set($key, $result, false, 86400); // Store the result of the query for a day return $result; }
  • 15. Common Use cases - 3Throttle user activity $key = “some:unique:key”; if ($memcache->get($key)) { //Deny access return false; } else { $memcache->set($key, “1”, false, 60); //Allow access return true; }
  • 16. Tips for OptimizationPre warm your cache using scripts Batch your requests using multi-get values= get(Array(“Foo”,”Bar”,”Baz”))Cache things other than SQL data! XML, HTML, Page fragmentsReplicate data across clustersDo set/delete in multiple clusters  Read from either clusterRun multiple instances on the same serverIf you know the data, implement a simple encoding scheme
  • 17. Using Memcache in WordPressDownload Memcached Object Cache Plugin from http://wordpress.org/extend/plugins/memcached/Set up memcached serversInstall peclmemcacheextentionCopy object-cache.php to wp-content directory (not the Pluing’s directory)You are done 