SlideShare a Scribd company logo
CHI: Universal caching
      for Perl
       Jonathan Swartz
        YAPC|10 2009
        Pittsburgh, PA
What is CHI?

• Standard interface and implementation for
  Perl caches - aka 'DBI for caching'
• Inspired by Cache::Cache, but improves
  performance and extendibility
Why do we need it?

• CPAN modules that need cache can simply
  ask for a CHI handle
• Implement generic caching features in a
  single place
• Make new cache backends trivial to create
Modules that just need
     "a cache"'
• Templating: HTML::Mason, Template::Toolkit
• Web frameworks: Catalyst, CGI::Application
• Sessions: CGI::Session, Apache::Session
• ORMs: Data::ObjectDriver, Rose::DB::Object
• Code processing: Perl::Tidy, Perl::Critic
• Startup impaired: Class::MOP/Moose
Basic API
# Choose a driver
#
my $cache = CHI->new( driver => 'Memory' );
my $cache = CHI->new(
    driver     => 'File',
    cache_root => '/path/to/root'
);
my $cache = CHI->new(
    driver     => 'FastMmap',
    root_dir   => '/path/to/root',
    cache_size => '1k'
);

# Get and set items
#
my $customer = $cache->get($name);
if ( !defined $customer ) {
    $customer = get_customer_from_db($name);
    $cache->set( $name, $customer, "10 minutes" );
}
$cache->remove($name);
Current CHI drivers
•   Memory - In-process memory

•   File - Hierarchical, one file per entry

•   FastMmap - Mmap'ed files

•   Memcached

•   DBI

•   BerkeleyDB

•   CacheCache - Any existing Cache::Cache driver
Driver skeleton
package CHI::Driver::MyDriver;
use Moose;
extends 'CHI::Driver';
has 'attr' => ( ... );

sub fetch {
    my ( $self, $key ) = @_;

sub store {
    my ( $self, $key, $data ) = @_;

sub remove {
    my ( $self, $key ) = @_;

sub clear {
    my ($self) = @_;

sub get_keys {
    my ($self) = @_;

sub get_namespaces {
    my ($self) = @_;
Avoiding miss stampedes

• Problem: Many processes try to recompute
   cache when it expires
• Solution 1: Probabilistic expiration
 my $cache = CHI->new(..., expires_variance => 0.20);


• Solution 2: Busy locks
 my $cache = CHI->new(..., busy_lock => '30 sec');
Recomputation latency
•   Problem: Client waits while data is recomputed

•   Solution 1: Background recomputation
my $customer = $cache->compute( $name,
      sub { get_customer_from_db($name) }, "10 minutes" );


•   Solution 2: Externally initiated recomputation
use LWP::Simple;
foreach my $url (@common_urls) {
    # recompute_cache temporarily reduces expiration
    get("http://www.mysite.com/$url?recompute_cache=1");
}
Multilevel caches
•   Several caches can be chained together

•   Example 1: L1 cache in front of memcached
my $cache = CHI->new(
    driver   => 'Memcached',
    servers => [ "10.0.0.15:11211", ... ],
    l1_cache => { driver => 'Memory', max_size => '1MB' } );


•   Example 2: Mirror cache to migrate cache directories
my $cache = CHI->new(
    driver   => 'File',
    root_dir => '/old/root' mirror_cache =>
      { driver => 'File', root_dir => '/new/root' } );
To do
•   Cache statistics - collection and reporting

•   Registry of storage types (like Rose::DB) with
    memoization

•   Background recomputation

•   Close performance gap between CHI and native

•   Plugins for Catalyst, CGI::Session, etc.
Additional resources

• Download CHI from CPAN -
  http://cpan.uwinnipeg.ca/dist/CHI

• Search for drivers -
  http://cpan.uwinnipeg.ca/search?query=CHI::Driver

• Subscribe to perl-cache mailing list -
  http://groups.google.com/group/perl-cache-discuss

More Related Content

What's hot

Node.js - As a networking tool
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking tool
Felix Geisendörfer
 
Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?
Felix Geisendörfer
 
Nodejs - A quick tour (v4)
Nodejs - A quick tour (v4)Nodejs - A quick tour (v4)
Nodejs - A quick tour (v4)
Felix Geisendörfer
 
Elasticsearch 1.x Cluster Installation (VirtualBox)
Elasticsearch 1.x Cluster Installation (VirtualBox)Elasticsearch 1.x Cluster Installation (VirtualBox)
Elasticsearch 1.x Cluster Installation (VirtualBox)
Amir Sedighi
 
Highload осень 2012 лекция 3
Highload осень 2012 лекция 3Highload осень 2012 лекция 3
Highload осень 2012 лекция 3
Technopark
 
Scaling WordPress On A Small Budget
Scaling WordPress On A Small BudgetScaling WordPress On A Small Budget
Scaling WordPress On A Small Budget
Brecht Ryckaert
 
Building low latency java applications with ehcache
Building low latency java applications with ehcacheBuilding low latency java applications with ehcache
Building low latency java applications with ehcache
Chris Westin
 
Sofia WP User Group Presentation
Sofia WP User Group PresentationSofia WP User Group Presentation
Sofia WP User Group Presentation
Daniel Kanchev
 
Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)
Felix Geisendörfer
 
Memcached
MemcachedMemcached
Banquet 36
Banquet 36Banquet 36
Banquet 36
Koubei UED
 
Node.js - A practical introduction (v2)
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)
Felix Geisendörfer
 
Drupal 8 Cache: Under the hood
Drupal 8 Cache: Under the hoodDrupal 8 Cache: Under the hood
Drupal 8 Cache: Under the hood
Piyuesh Kumar
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
Marc Cortinas Val
 
Node.js - A Quick Tour II
Node.js - A Quick Tour IINode.js - A Quick Tour II
Node.js - A Quick Tour II
Felix Geisendörfer
 
Scalability at GROU.PS
Scalability at GROU.PSScalability at GROU.PS
Scalability at GROU.PS
esokullu
 
Caching
CachingCaching
Caching
Nascenia IT
 
To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)
Geoffrey Anderson
 
Automating with Ansible
Automating with AnsibleAutomating with Ansible
Automating with Ansible
Ricardo Schmidt
 
Azure Recovery Services
Azure Recovery ServicesAzure Recovery Services
Azure Recovery Services
Pavel Revenkov
 

What's hot (20)

Node.js - As a networking tool
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking tool
 
Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?
 
Nodejs - A quick tour (v4)
Nodejs - A quick tour (v4)Nodejs - A quick tour (v4)
Nodejs - A quick tour (v4)
 
Elasticsearch 1.x Cluster Installation (VirtualBox)
Elasticsearch 1.x Cluster Installation (VirtualBox)Elasticsearch 1.x Cluster Installation (VirtualBox)
Elasticsearch 1.x Cluster Installation (VirtualBox)
 
Highload осень 2012 лекция 3
Highload осень 2012 лекция 3Highload осень 2012 лекция 3
Highload осень 2012 лекция 3
 
Scaling WordPress On A Small Budget
Scaling WordPress On A Small BudgetScaling WordPress On A Small Budget
Scaling WordPress On A Small Budget
 
Building low latency java applications with ehcache
Building low latency java applications with ehcacheBuilding low latency java applications with ehcache
Building low latency java applications with ehcache
 
Sofia WP User Group Presentation
Sofia WP User Group PresentationSofia WP User Group Presentation
Sofia WP User Group Presentation
 
Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)
 
Memcached
MemcachedMemcached
Memcached
 
Banquet 36
Banquet 36Banquet 36
Banquet 36
 
Node.js - A practical introduction (v2)
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)
 
Drupal 8 Cache: Under the hood
Drupal 8 Cache: Under the hoodDrupal 8 Cache: Under the hood
Drupal 8 Cache: Under the hood
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
Node.js - A Quick Tour II
Node.js - A Quick Tour IINode.js - A Quick Tour II
Node.js - A Quick Tour II
 
Scalability at GROU.PS
Scalability at GROU.PSScalability at GROU.PS
Scalability at GROU.PS
 
Caching
CachingCaching
Caching
 
To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)
 
Automating with Ansible
Automating with AnsibleAutomating with Ansible
Automating with Ansible
 
Azure Recovery Services
Azure Recovery ServicesAzure Recovery Services
Azure Recovery Services
 

Viewers also liked

Chiaccherata sulla democrazia partecipata
Chiaccherata sulla democrazia partecipataChiaccherata sulla democrazia partecipata
Chiaccherata sulla democrazia partecipata
Gianluigi Cogo
 
Zadar digit presentation
Zadar digit presentationZadar digit presentation
Zadar digit presentation
Spotted by Locals
 
Canal yoga-kit-iniciante
Canal yoga-kit-inicianteCanal yoga-kit-iniciante
Canal yoga-kit-iniciante
ilidia elisa queiros
 
Uspto reexamination request - update - august 8th to august 14th, 2012 - in...
Uspto   reexamination request - update - august 8th to august 14th, 2012 - in...Uspto   reexamination request - update - august 8th to august 14th, 2012 - in...
Uspto reexamination request - update - august 8th to august 14th, 2012 - in...
InvnTree IP Services Pvt. Ltd.
 
Portfolio For Library Course By Teng Miao(Eric)
Portfolio For Library Course By Teng Miao(Eric)Portfolio For Library Course By Teng Miao(Eric)
Portfolio For Library Course By Teng Miao(Eric)
guestac1d7c
 
Contract
ContractContract
Contract
Jodi Dean
 

Viewers also liked (7)

Chiaccherata sulla democrazia partecipata
Chiaccherata sulla democrazia partecipataChiaccherata sulla democrazia partecipata
Chiaccherata sulla democrazia partecipata
 
Zadar digit presentation
Zadar digit presentationZadar digit presentation
Zadar digit presentation
 
Routing 7
Routing 7Routing 7
Routing 7
 
Canal yoga-kit-iniciante
Canal yoga-kit-inicianteCanal yoga-kit-iniciante
Canal yoga-kit-iniciante
 
Uspto reexamination request - update - august 8th to august 14th, 2012 - in...
Uspto   reexamination request - update - august 8th to august 14th, 2012 - in...Uspto   reexamination request - update - august 8th to august 14th, 2012 - in...
Uspto reexamination request - update - august 8th to august 14th, 2012 - in...
 
Portfolio For Library Course By Teng Miao(Eric)
Portfolio For Library Course By Teng Miao(Eric)Portfolio For Library Course By Teng Miao(Eric)
Portfolio For Library Course By Teng Miao(Eric)
 
Contract
ContractContract
Contract
 

Similar to CHI-YAPC-2009

phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
Wim Godden
 
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
Wim Godden
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
Elizabeth Smith
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
Ben Ramsey
 
Zend Server Data Caching
Zend Server Data CachingZend Server Data Caching
Zend Server Data Caching
El Taller Web
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
Concentric Sky
 
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
Wim Godden
 
MUC - Moodle Universal Cache
MUC - Moodle Universal CacheMUC - Moodle Universal Cache
MUC - Moodle Universal Cache
Tim Hunt
 
Zend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsZend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applications
Enrico Zimuel
 
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPBottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMP
katzgrau
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
CodeIgniter Conference
 
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
Wim Godden
 
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
Wim Godden
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
Jurriaan Persyn
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
Ulf Wendel
 
Memcached Presentation @757rb
Memcached Presentation @757rbMemcached Presentation @757rb
Memcached Presentation @757rb
Ken Collins
 
Say YES to Premature Optimizations
Say YES to Premature OptimizationsSay YES to Premature Optimizations
Say YES to Premature Optimizations
Maude Lemaire
 
Dutch php conference_apc_mem2010
Dutch php conference_apc_mem2010Dutch php conference_apc_mem2010
Dutch php conference_apc_mem2010
isnull
 
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
Wim Godden
 
Drupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case StudyDrupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case Study
hernanibf
 

Similar to CHI-YAPC-2009 (20)

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
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 
Zend Server Data Caching
Zend Server Data CachingZend Server Data Caching
Zend Server Data Caching
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
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
 
MUC - Moodle Universal Cache
MUC - Moodle Universal CacheMUC - Moodle Universal Cache
MUC - Moodle Universal Cache
 
Zend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsZend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applications
 
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPBottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMP
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
 
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
 
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
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
Memcached Presentation @757rb
Memcached Presentation @757rbMemcached Presentation @757rb
Memcached Presentation @757rb
 
Say YES to Premature Optimizations
Say YES to Premature OptimizationsSay YES to Premature Optimizations
Say YES to Premature Optimizations
 
Dutch php conference_apc_mem2010
Dutch php conference_apc_mem2010Dutch php conference_apc_mem2010
Dutch php conference_apc_mem2010
 
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
 
Drupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case StudyDrupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case Study
 

Recently uploaded

Euro 2024 Quarterfinal Showdowns and Star Performances Highlight Prestigious ...
Euro 2024 Quarterfinal Showdowns and Star Performances Highlight Prestigious ...Euro 2024 Quarterfinal Showdowns and Star Performances Highlight Prestigious ...
Euro 2024 Quarterfinal Showdowns and Star Performances Highlight Prestigious ...
Eticketing.co
 
THALA FOR A REASON Quiz set by Diganta Palit
THALA FOR A REASON Quiz set by Diganta PalitTHALA FOR A REASON Quiz set by Diganta Palit
THALA FOR A REASON Quiz set by Diganta Palit
digantasahitya
 
The Paris Olympic Opening Ceremony Starting Date and Time.pdf
The Paris Olympic Opening Ceremony Starting Date and Time.pdfThe Paris Olympic Opening Ceremony Starting Date and Time.pdf
The Paris Olympic Opening Ceremony Starting Date and Time.pdf
Eticketing.co
 
Paris 2024 Morocco Unveils Final Squad for Olympic Paris Football Tournament.pdf
Paris 2024 Morocco Unveils Final Squad for Olympic Paris Football Tournament.pdfParis 2024 Morocco Unveils Final Squad for Olympic Paris Football Tournament.pdf
Paris 2024 Morocco Unveils Final Squad for Olympic Paris Football Tournament.pdf
Eticketing.co
 
Girls Call Jb Nagar 9910780858 Provide Best And Top Girl Service And No1 in City
Girls Call Jb Nagar 9910780858 Provide Best And Top Girl Service And No1 in CityGirls Call Jb Nagar 9910780858 Provide Best And Top Girl Service And No1 in City
Girls Call Jb Nagar 9910780858 Provide Best And Top Girl Service And No1 in City
margaretblush
 
Euro 2024 Predictions - Quarter Final Results.pptx
Euro 2024 Predictions - Quarter Final Results.pptxEuro 2024 Predictions - Quarter Final Results.pptx
Euro 2024 Predictions - Quarter Final Results.pptx
Select Distinct Limited
 
Euro Cup 2024 Quarter Finals Spain's Young Stars Face Germany's Wonder Kids, ...
Euro Cup 2024 Quarter Finals Spain's Young Stars Face Germany's Wonder Kids, ...Euro Cup 2024 Quarter Finals Spain's Young Stars Face Germany's Wonder Kids, ...
Euro Cup 2024 Quarter Finals Spain's Young Stars Face Germany's Wonder Kids, ...
Eticketing.co
 
Female Girls call Pune 000XX00000 Provide Best And Top Girl Service And No1 i...
Female Girls call Pune 000XX00000 Provide Best And Top Girl Service And No1 i...Female Girls call Pune 000XX00000 Provide Best And Top Girl Service And No1 i...
Female Girls call Pune 000XX00000 Provide Best And Top Girl Service And No1 i...
bhumivarma35300
 
Guwahati Girls Call Guwahati 0X0000000X Unlimited Short Providing Girls Servi...
Guwahati Girls Call Guwahati 0X0000000X Unlimited Short Providing Girls Servi...Guwahati Girls Call Guwahati 0X0000000X Unlimited Short Providing Girls Servi...
Guwahati Girls Call Guwahati 0X0000000X Unlimited Short Providing Girls Servi...
aparnaseth12
 
Euro Cup 2024 France and Spain Triumph, England and Netherlands Brace for Qua...
Euro Cup 2024 France and Spain Triumph, England and Netherlands Brace for Qua...Euro Cup 2024 France and Spain Triumph, England and Netherlands Brace for Qua...
Euro Cup 2024 France and Spain Triumph, England and Netherlands Brace for Qua...
Eticketing.co
 
Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And No1 i...
Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And No1 i...Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And No1 i...
Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And No1 i...
dizzycaye
 
Olympics 2024 Tickets: A Fashion-Forward Opening Ceremony
Olympics 2024 Tickets: A Fashion-Forward Opening CeremonyOlympics 2024 Tickets: A Fashion-Forward Opening Ceremony
Olympics 2024 Tickets: A Fashion-Forward Opening Ceremony
Eticketing.co
 
Sports Psychology slides for presentation with WAFSU.org
Sports Psychology slides for presentation with WAFSU.orgSports Psychology slides for presentation with WAFSU.org
Sports Psychology slides for presentation with WAFSU.org
Mark Rauterkus
 
NRI Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
NRI Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...NRI Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
NRI Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
rhiannateal
 
Spain and France Secure Euro 2024 Semi-Final Spots.pdf
Spain and France Secure Euro 2024 Semi-Final Spots.pdfSpain and France Secure Euro 2024 Semi-Final Spots.pdf
Spain and France Secure Euro 2024 Semi-Final Spots.pdf
Euro Cup 2024 Tickets
 
Top Olympics Athelets of 2024 (Road to Glory)
Top Olympics Athelets of 2024 (Road to Glory)Top Olympics Athelets of 2024 (Road to Glory)
Top Olympics Athelets of 2024 (Road to Glory)
Shubham Pant
 
SEMIFINALES LIGA MURO 2024BASQUETBOL.pdf
SEMIFINALES LIGA MURO 2024BASQUETBOL.pdfSEMIFINALES LIGA MURO 2024BASQUETBOL.pdf
SEMIFINALES LIGA MURO 2024BASQUETBOL.pdf
Arturo Pacheco Alvarez
 
Ruben Dominguez on Developing Fans, Telling Stories, and Elevating the Brand ...
Ruben Dominguez on Developing Fans, Telling Stories, and Elevating the Brand ...Ruben Dominguez on Developing Fans, Telling Stories, and Elevating the Brand ...
Ruben Dominguez on Developing Fans, Telling Stories, and Elevating the Brand ...
Neil Horowitz
 
Paris 2024 France Names Men's Football Squad for Olympic Paris.pdf
Paris 2024 France Names Men's Football Squad for Olympic Paris.pdfParis 2024 France Names Men's Football Squad for Olympic Paris.pdf
Paris 2024 France Names Men's Football Squad for Olympic Paris.pdf
Eticketing.co
 
Which Euro 2024 Legends Will Shine at the FIFA World Cup 2026.docx
Which Euro 2024 Legends Will Shine at the FIFA World Cup 2026.docxWhich Euro 2024 Legends Will Shine at the FIFA World Cup 2026.docx
Which Euro 2024 Legends Will Shine at the FIFA World Cup 2026.docx
FIFA world Cup
 

Recently uploaded (20)

Euro 2024 Quarterfinal Showdowns and Star Performances Highlight Prestigious ...
Euro 2024 Quarterfinal Showdowns and Star Performances Highlight Prestigious ...Euro 2024 Quarterfinal Showdowns and Star Performances Highlight Prestigious ...
Euro 2024 Quarterfinal Showdowns and Star Performances Highlight Prestigious ...
 
THALA FOR A REASON Quiz set by Diganta Palit
THALA FOR A REASON Quiz set by Diganta PalitTHALA FOR A REASON Quiz set by Diganta Palit
THALA FOR A REASON Quiz set by Diganta Palit
 
The Paris Olympic Opening Ceremony Starting Date and Time.pdf
The Paris Olympic Opening Ceremony Starting Date and Time.pdfThe Paris Olympic Opening Ceremony Starting Date and Time.pdf
The Paris Olympic Opening Ceremony Starting Date and Time.pdf
 
Paris 2024 Morocco Unveils Final Squad for Olympic Paris Football Tournament.pdf
Paris 2024 Morocco Unveils Final Squad for Olympic Paris Football Tournament.pdfParis 2024 Morocco Unveils Final Squad for Olympic Paris Football Tournament.pdf
Paris 2024 Morocco Unveils Final Squad for Olympic Paris Football Tournament.pdf
 
Girls Call Jb Nagar 9910780858 Provide Best And Top Girl Service And No1 in City
Girls Call Jb Nagar 9910780858 Provide Best And Top Girl Service And No1 in CityGirls Call Jb Nagar 9910780858 Provide Best And Top Girl Service And No1 in City
Girls Call Jb Nagar 9910780858 Provide Best And Top Girl Service And No1 in City
 
Euro 2024 Predictions - Quarter Final Results.pptx
Euro 2024 Predictions - Quarter Final Results.pptxEuro 2024 Predictions - Quarter Final Results.pptx
Euro 2024 Predictions - Quarter Final Results.pptx
 
Euro Cup 2024 Quarter Finals Spain's Young Stars Face Germany's Wonder Kids, ...
Euro Cup 2024 Quarter Finals Spain's Young Stars Face Germany's Wonder Kids, ...Euro Cup 2024 Quarter Finals Spain's Young Stars Face Germany's Wonder Kids, ...
Euro Cup 2024 Quarter Finals Spain's Young Stars Face Germany's Wonder Kids, ...
 
Female Girls call Pune 000XX00000 Provide Best And Top Girl Service And No1 i...
Female Girls call Pune 000XX00000 Provide Best And Top Girl Service And No1 i...Female Girls call Pune 000XX00000 Provide Best And Top Girl Service And No1 i...
Female Girls call Pune 000XX00000 Provide Best And Top Girl Service And No1 i...
 
Guwahati Girls Call Guwahati 0X0000000X Unlimited Short Providing Girls Servi...
Guwahati Girls Call Guwahati 0X0000000X Unlimited Short Providing Girls Servi...Guwahati Girls Call Guwahati 0X0000000X Unlimited Short Providing Girls Servi...
Guwahati Girls Call Guwahati 0X0000000X Unlimited Short Providing Girls Servi...
 
Euro Cup 2024 France and Spain Triumph, England and Netherlands Brace for Qua...
Euro Cup 2024 France and Spain Triumph, England and Netherlands Brace for Qua...Euro Cup 2024 France and Spain Triumph, England and Netherlands Brace for Qua...
Euro Cup 2024 France and Spain Triumph, England and Netherlands Brace for Qua...
 
Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And No1 i...
Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And No1 i...Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And No1 i...
Girls Call Navi Mumbai 9930245274 Provide Best And Top Girl Service And No1 i...
 
Olympics 2024 Tickets: A Fashion-Forward Opening Ceremony
Olympics 2024 Tickets: A Fashion-Forward Opening CeremonyOlympics 2024 Tickets: A Fashion-Forward Opening Ceremony
Olympics 2024 Tickets: A Fashion-Forward Opening Ceremony
 
Sports Psychology slides for presentation with WAFSU.org
Sports Psychology slides for presentation with WAFSU.orgSports Psychology slides for presentation with WAFSU.org
Sports Psychology slides for presentation with WAFSU.org
 
NRI Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
NRI Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...NRI Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
NRI Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 in...
 
Spain and France Secure Euro 2024 Semi-Final Spots.pdf
Spain and France Secure Euro 2024 Semi-Final Spots.pdfSpain and France Secure Euro 2024 Semi-Final Spots.pdf
Spain and France Secure Euro 2024 Semi-Final Spots.pdf
 
Top Olympics Athelets of 2024 (Road to Glory)
Top Olympics Athelets of 2024 (Road to Glory)Top Olympics Athelets of 2024 (Road to Glory)
Top Olympics Athelets of 2024 (Road to Glory)
 
SEMIFINALES LIGA MURO 2024BASQUETBOL.pdf
SEMIFINALES LIGA MURO 2024BASQUETBOL.pdfSEMIFINALES LIGA MURO 2024BASQUETBOL.pdf
SEMIFINALES LIGA MURO 2024BASQUETBOL.pdf
 
Ruben Dominguez on Developing Fans, Telling Stories, and Elevating the Brand ...
Ruben Dominguez on Developing Fans, Telling Stories, and Elevating the Brand ...Ruben Dominguez on Developing Fans, Telling Stories, and Elevating the Brand ...
Ruben Dominguez on Developing Fans, Telling Stories, and Elevating the Brand ...
 
Paris 2024 France Names Men's Football Squad for Olympic Paris.pdf
Paris 2024 France Names Men's Football Squad for Olympic Paris.pdfParis 2024 France Names Men's Football Squad for Olympic Paris.pdf
Paris 2024 France Names Men's Football Squad for Olympic Paris.pdf
 
Which Euro 2024 Legends Will Shine at the FIFA World Cup 2026.docx
Which Euro 2024 Legends Will Shine at the FIFA World Cup 2026.docxWhich Euro 2024 Legends Will Shine at the FIFA World Cup 2026.docx
Which Euro 2024 Legends Will Shine at the FIFA World Cup 2026.docx
 

CHI-YAPC-2009

  • 1. CHI: Universal caching for Perl Jonathan Swartz YAPC|10 2009 Pittsburgh, PA
  • 2. What is CHI? • Standard interface and implementation for Perl caches - aka 'DBI for caching' • Inspired by Cache::Cache, but improves performance and extendibility
  • 3. Why do we need it? • CPAN modules that need cache can simply ask for a CHI handle • Implement generic caching features in a single place • Make new cache backends trivial to create
  • 4. Modules that just need "a cache"' • Templating: HTML::Mason, Template::Toolkit • Web frameworks: Catalyst, CGI::Application • Sessions: CGI::Session, Apache::Session • ORMs: Data::ObjectDriver, Rose::DB::Object • Code processing: Perl::Tidy, Perl::Critic • Startup impaired: Class::MOP/Moose
  • 5. Basic API # Choose a driver # my $cache = CHI->new( driver => 'Memory' ); my $cache = CHI->new( driver => 'File', cache_root => '/path/to/root' ); my $cache = CHI->new( driver => 'FastMmap', root_dir => '/path/to/root', cache_size => '1k' ); # Get and set items # my $customer = $cache->get($name); if ( !defined $customer ) { $customer = get_customer_from_db($name); $cache->set( $name, $customer, "10 minutes" ); } $cache->remove($name);
  • 6. Current CHI drivers • Memory - In-process memory • File - Hierarchical, one file per entry • FastMmap - Mmap'ed files • Memcached • DBI • BerkeleyDB • CacheCache - Any existing Cache::Cache driver
  • 7. Driver skeleton package CHI::Driver::MyDriver; use Moose; extends 'CHI::Driver'; has 'attr' => ( ... ); sub fetch { my ( $self, $key ) = @_; sub store { my ( $self, $key, $data ) = @_; sub remove { my ( $self, $key ) = @_; sub clear { my ($self) = @_; sub get_keys { my ($self) = @_; sub get_namespaces { my ($self) = @_;
  • 8. Avoiding miss stampedes • Problem: Many processes try to recompute cache when it expires • Solution 1: Probabilistic expiration my $cache = CHI->new(..., expires_variance => 0.20); • Solution 2: Busy locks my $cache = CHI->new(..., busy_lock => '30 sec');
  • 9. Recomputation latency • Problem: Client waits while data is recomputed • Solution 1: Background recomputation my $customer = $cache->compute( $name, sub { get_customer_from_db($name) }, "10 minutes" ); • Solution 2: Externally initiated recomputation use LWP::Simple; foreach my $url (@common_urls) { # recompute_cache temporarily reduces expiration get("http://www.mysite.com/$url?recompute_cache=1"); }
  • 10. Multilevel caches • Several caches can be chained together • Example 1: L1 cache in front of memcached my $cache = CHI->new( driver => 'Memcached', servers => [ "10.0.0.15:11211", ... ], l1_cache => { driver => 'Memory', max_size => '1MB' } ); • Example 2: Mirror cache to migrate cache directories my $cache = CHI->new( driver => 'File', root_dir => '/old/root' mirror_cache => { driver => 'File', root_dir => '/new/root' } );
  • 11. To do • Cache statistics - collection and reporting • Registry of storage types (like Rose::DB) with memoization • Background recomputation • Close performance gap between CHI and native • Plugins for Catalyst, CGI::Session, etc.
  • 12. Additional resources • Download CHI from CPAN - http://cpan.uwinnipeg.ca/dist/CHI • Search for drivers - http://cpan.uwinnipeg.ca/search?query=CHI::Driver • Subscribe to perl-cache mailing list - http://groups.google.com/group/perl-cache-discuss