SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Caching Data For Performance Dave Ross West Suburban Chicago PHP Meetup February 7, 2008
Caching It's faster to get information from somewhere close...
Caching Than somewhere far away.
It's all about scalability. (seriously)
Where? Generally speaking... Local Database faster than Shared Database Local Disk faster than Database RAM faster than Disk
What? Anything you don't want to fetch or compute every time your code runs. Anything that isn't going to change very often.
Everybody's Doing It! ,[object Object],[object Object],[object Object]
Even PHP Itself Is Getting Cached ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A Few Things I Cached Recently ,[object Object],[object Object],[object Object]
Caching On Disk Make a big array of the data you need. // At the start of your script $array = unserialize(file_get_contents($fileName)); // If the data isn't already there, put it there if(array_key_exists('key', $array)) { $value = $array['key']; } else { // Retrieve or compute $value $value = “Hello, World!”; $array['key'] = $value; } // At the end of your script file_put_contents($fileName, serialize($array));
Of Course, the OS Caches Files Modern operating systems use all your free RAM as a disk cache. If you read the same file over & over, it's probably being read out of RAM the second time on. So, it's usually ok to read a small file over & over.
memcached “ memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.”
memcached (It's a big array that doesn't go away when your PHP program ends.)
memcached <?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die (&quot;Could not connect&quot;); $version = $memcache->getVersion(); echo &quot;Server's version: &quot;.$version.&quot;<br/>&quot;; $tmp_object = new stdClass; $tmp_object->str_attr = 'test'; $tmp_object->int_attr = 123; $memcache->set('key', $tmp_object, false, 10) or die (&quot;Failed to save data at the server&quot;); echo &quot;Store data in the cache (data will expire in 10 seconds)<br/>&quot;; $get_result = $memcache->get('key'); echo &quot;Data from the cache:<br/>&quot;; var_dump($get_result); ?>
Caveats Be careful caching anything where security matters. Don't cache credit card info (PCI compliance) Keep cache up-to-date (when data changes)
For More Information ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

PHP Performance with APC + Memcached
PHP Performance with APC + MemcachedPHP Performance with APC + Memcached
PHP Performance with APC + Memcached
Ford AntiTrust
 
From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Cluster
guestd34230
 
Caching for Cash: Caching
Caching for Cash: CachingCaching for Cash: Caching
Caching for Cash: Caching
Scott MacVicar
 
Phorum MySQL tricks
Phorum MySQL tricksPhorum MySQL tricks
Phorum MySQL tricks
guestd34230
 
Caching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and ProfilingCaching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and Profiling
Scott MacVicar
 

Was ist angesagt? (20)

PHP Performance with APC + Memcached
PHP Performance with APC + MemcachedPHP Performance with APC + Memcached
PHP Performance with APC + Memcached
 
High Performance Wordpress
High Performance WordpressHigh Performance Wordpress
High Performance Wordpress
 
Varnish bof
Varnish bofVarnish bof
Varnish bof
 
From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Cluster
 
Caching for Cash: Caching
Caching for Cash: CachingCaching for Cash: Caching
Caching for Cash: Caching
 
Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applications
 
Building Scalable Web Apps - LVL.UP KL
Building Scalable Web Apps - LVL.UP KLBuilding Scalable Web Apps - LVL.UP KL
Building Scalable Web Apps - LVL.UP KL
 
Phorum MySQL tricks
Phorum MySQL tricksPhorum MySQL tricks
Phorum MySQL tricks
 
WP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-NapocaWP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-Napoca
 
Cache all the things - A guide to caching Drupal
Cache all the things - A guide to caching DrupalCache all the things - A guide to caching Drupal
Cache all the things - A guide to caching Drupal
 
Memcache
MemcacheMemcache
Memcache
 
Drupal7 MEMCACHE
Drupal7 MEMCACHE Drupal7 MEMCACHE
Drupal7 MEMCACHE
 
Caching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and ProfilingCaching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and Profiling
 
Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cacheMini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
 
Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2
 
Scaling symfony apps
Scaling symfony appsScaling symfony apps
Scaling symfony apps
 
Caching
CachingCaching
Caching
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
 
Using memcache to improve php performance
Using memcache to improve php performanceUsing memcache to improve php performance
Using memcache to improve php performance
 
High Availabiltity & Replica Sets with mongoDB
High Availabiltity & Replica Sets with mongoDBHigh Availabiltity & Replica Sets with mongoDB
High Availabiltity & Replica Sets with mongoDB
 

Andere mochten auch

MoodleMoot Brasil 2011 - O Moodle na UFSC (Infraestrutura de TI)
MoodleMoot Brasil 2011 - O Moodle na UFSC (Infraestrutura de TI)MoodleMoot Brasil 2011 - O Moodle na UFSC (Infraestrutura de TI)
MoodleMoot Brasil 2011 - O Moodle na UFSC (Infraestrutura de TI)
Daniel Neis
 
SQL Server 簡易診断サービス ご紹介資料
SQL Server 簡易診断サービス ご紹介資料SQL Server 簡易診断サービス ご紹介資料
SQL Server 簡易診断サービス ご紹介資料
Masayuki Ozawa
 
SQL Server 現状診断サービス ご紹介資料
SQL Server 現状診断サービス ご紹介資料SQL Server 現状診断サービス ご紹介資料
SQL Server 現状診断サービス ご紹介資料
Masayuki Ozawa
 
[INSIGHT OUT 2011] C12 50分で理解する SQL Serverでできることできないこと(uchiyama)
[INSIGHT OUT 2011] C12 50分で理解する SQL Serverでできることできないこと(uchiyama)[INSIGHT OUT 2011] C12 50分で理解する SQL Serverでできることできないこと(uchiyama)
[INSIGHT OUT 2011] C12 50分で理解する SQL Serverでできることできないこと(uchiyama)
Insight Technology, Inc.
 
Sql server 構築 運用 tips
Sql server 構築 運用 tipsSql server 構築 運用 tips
Sql server 構築 運用 tips
Masayuki Ozawa
 
45分で理解する SQL Serverでできることできないこと
45分で理解する SQL Serverでできることできないこと45分で理解する SQL Serverでできることできないこと
45分で理解する SQL Serverでできることできないこと
Insight Technology, Inc.
 
Top 10 Interview Questions
Top 10 Interview QuestionsTop 10 Interview Questions
Top 10 Interview Questions
hawaiiscott
 

Andere mochten auch (20)

Van Gogh-Borges
Van Gogh-BorgesVan Gogh-Borges
Van Gogh-Borges
 
FRT Vol. 5 クラウド時代の企業アプリケーションとマーケティング
FRT Vol. 5 クラウド時代の企業アプリケーションとマーケティングFRT Vol. 5 クラウド時代の企業アプリケーションとマーケティング
FRT Vol. 5 クラウド時代の企業アプリケーションとマーケティング
 
Trabalhando com o Moodle e a Comunidade
Trabalhando com o Moodle e a ComunidadeTrabalhando com o Moodle e a Comunidade
Trabalhando com o Moodle e a Comunidade
 
Global Knowledge Training Courses & Promotion 2015-Sep
Global Knowledge Training Courses & Promotion 2015-SepGlobal Knowledge Training Courses & Promotion 2015-Sep
Global Knowledge Training Courses & Promotion 2015-Sep
 
STelligence Savvius Thai Datasheet
STelligence Savvius Thai DatasheetSTelligence Savvius Thai Datasheet
STelligence Savvius Thai Datasheet
 
MoodleMoot Brasil 2011 - O Moodle na UFSC (Infraestrutura de TI)
MoodleMoot Brasil 2011 - O Moodle na UFSC (Infraestrutura de TI)MoodleMoot Brasil 2011 - O Moodle na UFSC (Infraestrutura de TI)
MoodleMoot Brasil 2011 - O Moodle na UFSC (Infraestrutura de TI)
 
ThaiCert Phishing and Malicious Code Infographic 2015
ThaiCert Phishing and Malicious Code Infographic 2015ThaiCert Phishing and Malicious Code Infographic 2015
ThaiCert Phishing and Malicious Code Infographic 2015
 
SQL Server 簡易診断サービス ご紹介資料
SQL Server 簡易診断サービス ご紹介資料SQL Server 簡易診断サービス ご紹介資料
SQL Server 簡易診断サービス ご紹介資料
 
SQL Server 現状診断サービス ご紹介資料
SQL Server 現状診断サービス ご紹介資料SQL Server 現状診断サービス ご紹介資料
SQL Server 現状診断サービス ご紹介資料
 
OSSV [Open System SnapVault]
OSSV [Open System SnapVault]OSSV [Open System SnapVault]
OSSV [Open System SnapVault]
 
[INSIGHT OUT 2011] C12 50分で理解する SQL Serverでできることできないこと(uchiyama)
[INSIGHT OUT 2011] C12 50分で理解する SQL Serverでできることできないこと(uchiyama)[INSIGHT OUT 2011] C12 50分で理解する SQL Serverでできることできないこと(uchiyama)
[INSIGHT OUT 2011] C12 50分で理解する SQL Serverでできることできないこと(uchiyama)
 
Driver development – memory management
Driver development – memory managementDriver development – memory management
Driver development – memory management
 
Sql server 構築 運用 tips
Sql server 構築 運用 tipsSql server 構築 運用 tips
Sql server 構築 運用 tips
 
Board support package_on_linux
Board support package_on_linuxBoard support package_on_linux
Board support package_on_linux
 
45分で理解する SQL Serverでできることできないこと
45分で理解する SQL Serverでできることできないこと45分で理解する SQL Serverでできることできないこと
45分で理解する SQL Serverでできることできないこと
 
Sql server 運用 101
Sql server 運用 101Sql server 運用 101
Sql server 運用 101
 
Linux for embedded_systems
Linux for embedded_systemsLinux for embedded_systems
Linux for embedded_systems
 
Kernel module programming
Kernel module programmingKernel module programming
Kernel module programming
 
HANAのハナシの基本のき
HANAのハナシの基本のきHANAのハナシの基本のき
HANAのハナシの基本のき
 
Top 10 Interview Questions
Top 10 Interview QuestionsTop 10 Interview Questions
Top 10 Interview Questions
 

Ähnlich wie Caching Data For Performance

Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
Joseph Scott
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
drupalcampest
 
Jug Lugano - Scale over the limits
Jug Lugano - Scale over the limitsJug Lugano - Scale over the limits
Jug Lugano - Scale over the limits
Davide Carnevali
 
0628阙宏宇
0628阙宏宇0628阙宏宇
0628阙宏宇
zhu02
 

Ähnlich wie Caching Data For Performance (20)

Everyone loves PHP
Everyone loves PHPEveryone loves PHP
Everyone loves PHP
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
 
Caching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourCaching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTour
 
Lamp Stack Optimization
Lamp Stack OptimizationLamp Stack Optimization
Lamp Stack Optimization
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and Scalability
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 
Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 
Caching objects-in-memory
Caching objects-in-memoryCaching objects-in-memory
Caching objects-in-memory
 
MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
 
Jug Lugano - Scale over the limits
Jug Lugano - Scale over the limitsJug Lugano - Scale over the limits
Jug Lugano - Scale over the limits
 
0628阙宏宇
0628阙宏宇0628阙宏宇
0628阙宏宇
 

Mehr von Dave Ross

Stylesheets of the future with Sass and Compass
Stylesheets of the future with Sass and CompassStylesheets of the future with Sass and Compass
Stylesheets of the future with Sass and Compass
Dave Ross
 
Date and Time programming in PHP & Javascript
Date and Time programming in PHP & JavascriptDate and Time programming in PHP & Javascript
Date and Time programming in PHP & Javascript
Dave Ross
 
Web App Security: XSS and CSRF
Web App Security: XSS and CSRFWeb App Security: XSS and CSRF
Web App Security: XSS and CSRF
Dave Ross
 
The Mobile Web: A developer's perspective
The Mobile Web: A developer's perspectiveThe Mobile Web: A developer's perspective
The Mobile Web: A developer's perspective
Dave Ross
 
Balsamiq Mockups
Balsamiq MockupsBalsamiq Mockups
Balsamiq Mockups
Dave Ross
 
LAMP Optimization
LAMP OptimizationLAMP Optimization
LAMP Optimization
Dave Ross
 
Lint - PHP & Javascript Code Checking
Lint - PHP & Javascript Code CheckingLint - PHP & Javascript Code Checking
Lint - PHP & Javascript Code Checking
Dave Ross
 
Cufon - Javascript Font Replacement
Cufon - Javascript Font ReplacementCufon - Javascript Font Replacement
Cufon - Javascript Font Replacement
Dave Ross
 
PHP Output Buffering
PHP Output BufferingPHP Output Buffering
PHP Output Buffering
Dave Ross
 

Mehr von Dave Ross (20)

Stylesheets of the future with Sass and Compass
Stylesheets of the future with Sass and CompassStylesheets of the future with Sass and Compass
Stylesheets of the future with Sass and Compass
 
HTML5 History & Features
HTML5 History & FeaturesHTML5 History & Features
HTML5 History & Features
 
A geek's guide to getting hired
A geek's guide to getting hiredA geek's guide to getting hired
A geek's guide to getting hired
 
NoSQL & MongoDB
NoSQL & MongoDBNoSQL & MongoDB
NoSQL & MongoDB
 
Date and Time programming in PHP & Javascript
Date and Time programming in PHP & JavascriptDate and Time programming in PHP & Javascript
Date and Time programming in PHP & Javascript
 
Simulated Eye Tracking with Attention Wizard
Simulated Eye Tracking with Attention WizardSimulated Eye Tracking with Attention Wizard
Simulated Eye Tracking with Attention Wizard
 
What's new in HTML5?
What's new in HTML5?What's new in HTML5?
What's new in HTML5?
 
The Canvas Tag
The Canvas TagThe Canvas Tag
The Canvas Tag
 
Wordpress
WordpressWordpress
Wordpress
 
The FPDF Library
The FPDF LibraryThe FPDF Library
The FPDF Library
 
FirePHP
FirePHPFirePHP
FirePHP
 
Bayesian Inference using b8
Bayesian Inference using b8Bayesian Inference using b8
Bayesian Inference using b8
 
SQL Injection in PHP
SQL Injection in PHPSQL Injection in PHP
SQL Injection in PHP
 
Web App Security: XSS and CSRF
Web App Security: XSS and CSRFWeb App Security: XSS and CSRF
Web App Security: XSS and CSRF
 
The Mobile Web: A developer's perspective
The Mobile Web: A developer's perspectiveThe Mobile Web: A developer's perspective
The Mobile Web: A developer's perspective
 
Balsamiq Mockups
Balsamiq MockupsBalsamiq Mockups
Balsamiq Mockups
 
LAMP Optimization
LAMP OptimizationLAMP Optimization
LAMP Optimization
 
Lint - PHP & Javascript Code Checking
Lint - PHP & Javascript Code CheckingLint - PHP & Javascript Code Checking
Lint - PHP & Javascript Code Checking
 
Cufon - Javascript Font Replacement
Cufon - Javascript Font ReplacementCufon - Javascript Font Replacement
Cufon - Javascript Font Replacement
 
PHP Output Buffering
PHP Output BufferingPHP Output Buffering
PHP Output Buffering
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Caching Data For Performance

  • 1. Caching Data For Performance Dave Ross West Suburban Chicago PHP Meetup February 7, 2008
  • 2. Caching It's faster to get information from somewhere close...
  • 4. It's all about scalability. (seriously)
  • 5. Where? Generally speaking... Local Database faster than Shared Database Local Disk faster than Database RAM faster than Disk
  • 6. What? Anything you don't want to fetch or compute every time your code runs. Anything that isn't going to change very often.
  • 7.
  • 8.
  • 9.
  • 10. Caching On Disk Make a big array of the data you need. // At the start of your script $array = unserialize(file_get_contents($fileName)); // If the data isn't already there, put it there if(array_key_exists('key', $array)) { $value = $array['key']; } else { // Retrieve or compute $value $value = “Hello, World!”; $array['key'] = $value; } // At the end of your script file_put_contents($fileName, serialize($array));
  • 11. Of Course, the OS Caches Files Modern operating systems use all your free RAM as a disk cache. If you read the same file over & over, it's probably being read out of RAM the second time on. So, it's usually ok to read a small file over & over.
  • 12. memcached “ memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.”
  • 13. memcached (It's a big array that doesn't go away when your PHP program ends.)
  • 14. memcached <?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die (&quot;Could not connect&quot;); $version = $memcache->getVersion(); echo &quot;Server's version: &quot;.$version.&quot;<br/>&quot;; $tmp_object = new stdClass; $tmp_object->str_attr = 'test'; $tmp_object->int_attr = 123; $memcache->set('key', $tmp_object, false, 10) or die (&quot;Failed to save data at the server&quot;); echo &quot;Store data in the cache (data will expire in 10 seconds)<br/>&quot;; $get_result = $memcache->get('key'); echo &quot;Data from the cache:<br/>&quot;; var_dump($get_result); ?>
  • 15. Caveats Be careful caching anything where security matters. Don't cache credit card info (PCI compliance) Keep cache up-to-date (when data changes)
  • 16.