SlideShare a Scribd company logo
1 of 11
Download to read offline
White Paper:

A Practical Guide to Data
Caching with Zend Server
By Shahar Evron,
Product Manager, Zend Technologies, Inc.




                 Technical




April 2009




© 2009 Zend Technologies, Inc. All rights reserved.
White Paper | A Practical Guide to Data Caching with Zend Server



Table of Contents
     Introduction                                                       3
     Ok, how do I get started?                                          4
     But wait...                                                        6
     How do I decide what to cache, and how?                            6
     What do I cache?                                                   6
     How do I cache?                                                    6
     How long do I need to cache for?                                   7
     Programmatic Cache Invalidation                                    8
     Cache Namespacing                                                 10
     Summary                                                           11
     Where Next?                                                       11




© Zend Technologies, Inc.                                          2
White Paper | A Practical Guide to Data Caching with Zend Server


Introduction
When asked about the most significant methods to speed up PHP applications, most experts
would say “Cache, Cache and Cache”. There are a lot of optimizations that could be done to
PHP code that would make it run faster, but the most effective method to speed up PHP
execution is to simply execute less, and one of the best ways to achieve that is through
caching.
Zend Server provides several caching-related features, including Optimizer+ for byte-code
caching, full-page caching using Zend Page Cache, and the Data Cache API. To avoid
confusion, let's go over them quickly:
    •    Zend Optimizer+ performs byte-code optimization and caching. This speeds up PHP
         applications by eliminating the process of reading scripts from disk and compiling
         them, often resulting in a speedup of x2 – x3 times, depending on the application.
         Zend Optimizer+ runs automatically, and installing your application on top of Zend
         Server is all you need to do in order to enjoy its benefits.
    •    Zend Page Cache allows caching of entire PHP web pages, or more correctly put,
         entire HTTP responses sent out from PHP. Page Caching permits dramatically
         improving the performance of pages on web applications (sometimes running as high
         as 10x, 20x and even 100x times faster), while maintaining dynamic capabilities
         through an elaborate system of caching rules that could be based on request
         parameters and user session data. Page Caching also has the benefit of not requiring
         any code changes, and can be set up from the Zend Server UI.
    •    Zend Data Cache is a set of API functions enabling a developer to store and manage
         data items (PHP strings, arrays and other data) and even output elements in either
         disk-based cache or shared memory cache. Zend Data Cache allows for precision-
         guided caching when Page Caching is not an option. The provided API is easy-to-use
         on existing code, and in many cases a developer can skip existing code sections by
         simply wrapping them with caching APIs.
This whitepaper will demonstrate how to use the Zend Data Cache API in order to speed up a
typical PHP application.




© Zend Technologies, Inc.                                                                       3
White Paper | A Practical Guide to Data Caching with Zend Server


Ok, how do I get started?
Getting started with Zend Data Cache is extremely easy: The first functions you need to know
about are zend_shm_cache_fetch() and zend_shm_cache_store(). These two functions are
used for storing data in the shared-memory cache, and for fetching data from the cache.
Note: Zend Data Cache offers two storage modules: The shared memory (“shm”) module, and
the disk module. We will revisit the differences later on, but for now, you should know that all
functions mentioned here with the 'zend_shm' prefix are used for shared memory storage. For
each function mentioned, there is an exact twin with the 'zend_disk' prefix that preforms the
same actions for the disk-based cache. For the two functions mentioned above, there are the
zend_disk_cache_store() and zend_disk_cache_fetch() twin functions. For convenience, we
will only mention the shared memory functions here – but keep in mind that you can (and
should, in some situations) use the disk-based cache functions as well.
Since code speaks louder than words, consider the following piece of code taken from an
imaginary but typical blogging platform:


 1. function getRecentPosts($count = 5) {
              getRecentPosts(
 2.   // Get the PDO adapter for the DB
 3.                 myBlogDb::getPdoAdapter();
                            ::getPdoAdapter
      $dbAdapter = myBlogDb::getPdoAdapter();
 4.
 5.   // Build the query
 6.   $query = "SELECT title, author, pubdate FROM posts" .
 7.                                            ?";
                " ORDER BY pubdate DESC LIMIT ?";
 8.                   $dbAdapter- prepare($query);
      $dbStatement = $dbAdapter->prepare($query);
 9.
10.
10.   // Execute the query and put data into an array
11.
11.   $recentPosts = array();
12.       ($dbStatement execute(array($count)))
           $dbStatement-        (array($count
      if ($dbStatement->execute(array($count))) {
13.     while($post    $dbStatement- fetch(PDO::FETCH_ASSOC))
                                              ::FETCH_ASSOC
        while($post = $dbStatement->fetch(PDO::FETCH_ASSOC)) {
14.        $recentPosts[] = $post;
           $recentPosts[]   $post;
15.
15.     }
16.   }
17.
18.
18.           $recentPosts;
      return $recentPosts;
19.
19. }


This function is used to fetch an array of the most recent posts in our blog, and will fetch the
title, author and publication date for each one. This is done by running an SQL query and
placing the results into an array.
While the list of recent posts in a blog is dynamic, it is rarely changing (“rarely” is of course a
relative term – but even in a very busy blog, you are likely to get hundreds or thousands of
“reads” for each new post). This makes it a very good candidate for caching, it and should be
fairly easy to do:


 1. function getRecentPosts($count = 5) {
             getRecentPosts(
 2.   // Try to fetch from the cache first
 3.                  zend_shm_cache_fetch('recentposts');
      $recentPosts = zend_shm_cache_fetch('recentposts');
 4.
 5.      ($recentPosts     null)
      if ($recentPosts === null) {
 6.     // Get the PDO adapter for the DB
 7.                  myBlogDb::getPdoAdapter();
                             ::getPdoAdapter
        $dbAdapter = myBlogDb::getPdoAdapter();




© Zend Technologies, Inc.                                                                             4
White Paper | A Practical Guide to Data Caching with Zend Server


 8.
 9.     // Build the query
10.
10.     $query = "SELECT title, author, pubdate FROM posts" .
11.
11.                                              ?";
                  " ORDER BY pubdate DESC LIMIT ?";
12.
12.                     $dbAdapter- prepare($query);
        $dbStatement = $dbAdapter->prepare($query);
13.
13.
14.
14.     // Execute the query
15.
15.     $recentPosts = array();
16.
16.         ($dbStatement execute(array($count)))
             $dbStatement-        (array($count
        if ($dbStatement->execute(array($count))) {
17.
17.       while($post    $dbStatement- fetch(PDO::FETCH_ASSOC))
                                                ::FETCH_ASSOC
          while($post = $dbStatement->fetch(PDO::FETCH_ASSOC)) {
18.
18.          $recentPosts[]   $post;
             $recentPosts[] = $post;
19.
19.       }
20.
20.
21.
21.       // Store the results in cache
22.
22.       zend_shm_cache_store('recentposts', $recentPosts,
          zend_shm_cache_store('recentposts', $recentPosts,
23.
23.                       3600);
                     24 * 3600);
24.
24.     }
25.
25.   }
26.
27.
27.           $recentPosts;
      return $recentPosts;
28.
28. }


What has changed? We added three lines of code (not including blank lines and comments...)
and here is what we get:
   •     First, we try to fetch the list of recent posts from our shared memory cache. The list of
         recent posts is stored under a unique key – 'recentposts', which is passed as a
         parameter to the fetch() function (line 4).
   •     If the item does not exist, or is “stale” (in caching terms that means it has passed its
         expiry date), the function will return NULL. This allows us to check if valid data was
         returned from the cache (line 6). If the return value is NULL (note the triple-equal
         operator! this makes sure that we did not get an empty array, which might be a valid
         cached value in this case), we fetch the live data from our DB, as we did before.
   •     After fetching live data from the DB, we make sure to store it in our cache, under the
         'recentposts' key, for 24 hours (line 24). We only do this if the query was successfully
         executed.
   •     Whether the data came from the DB or from our cache, we return it as we always did.
         The function's signature did not change, and we do not need to modify other parts of
         the code.
This allows us to skip most of the code responsible for fetching the list of recent posts from the
DB, and only execute it once a day or so. This might seem like a small victory, but remember
that database queries are one of the biggest hurdles in the road for scalability and
performance. Each reduced query is a win.




© Zend Technologies, Inc.                                                                            5
White Paper | A Practical Guide to Data Caching with Zend Server


But wait...
Some of you have probably noticed, that our function takes an argument, and might return
different results depending on that argument. Ignoring this when caching the results might
result in unexpected data being returned.
This can be easily solved by using the $count parameter as part of the cache item key, like so:
29.
29. $recentPosts = zend_shm_cache_fetch("recentposts-{$count}");
                   zend_shm_cache_fetch("recentposts-{$count}");


Of course, you will need to make the same change in line 24 when storing the data. Now, we
will end up with different cached item for different values of the $count parameter. If we use
the same function to show the last 5 posts in the home page, but have a special page listing
the last 20 posts, they will both show the correct data.



How do I decide what to cache, and how?
See, that was simple. But the real trick when caching is not using the API – it's actually
deciding what to cache, using what storage method, and for how long.



What do I cache?
Deciding what to cache is probably once of the places where inexperienced developers go
wrong. After all, “premature optimization is the root of all evil”, and it's a pretty common evil
too. Many developers tend to spend hours optimizing pieces of code which they think might be
problematic, but in reality account for 0.02% of the application's execution time.
The smartest approach to caching would be to look for the slowest spots in your application,
and the best way to do that would be to use a combination of performance monitoring and
profiling tools – such as Zend Server's Monitor combined with Zend Studio's Profiler. You can
use those to detect the real bottlenecks in your application, and then proceed to eradicate
them by applying one of the possible caching techniques. It is usually also very useful to use a
benchmarking tool such as ab, siege or jMeter in order to quantify the effect of any
optimization you make – but take notice that sometimes under heavy production load, the
effect is way bigger than any synthetic benchmark might imply.
Another point you should keep in mind is that a 10% speedup on a page which accounts for
80% of your traffic (such as the home page on some applications) is usually way more
effective than a 70% speedup on a page which accounts for 2% of your traffic. You should
almost always start with the most popular parts of your application.



How do I cache?
Zend Server offers three caching methods: Page Cache, and two Data Cache storage
modules. Additionally, several other caching techniques are available out there (and as part of
Zend Server), such as memcache-based clustered cache and even PHP code generation
based caching. Each one of those techniques has its pros and cons, and while we will not
cover all of them in details here, let's do a quick overview of them:
    •    Zend Page Cache should be preferred if possible – being almost always the fastest of
         them all. Zend Server's Page Cache feature is quite flexible, but unfortunately, in
         some cases caching entire pages becomes inefficient – for example when a page's




© Zend Technologies, Inc.                                                                           6
White Paper | A Practical Guide to Data Caching with Zend Server


         content relies on too many factors and changes constantly, or when a change cannot
         be predicted based on request or session parameters.
    •    Zend Data Cache Shared Memory Storage should be the preferred method of
         caching small data items or pieces of output. It stores the data in a block of RAM on
         your server, which is shared by all the different PHP processes (be it Apache
         processes or FastCGI processes) and hence its name. This makes it very fast, but
         somewhat size limited; however, unless you're storing huge amounts of data in cache,
         you should have no problems.
    •    Zend Data Cache Disk Storage should be used when you need a relatively fast local
         cache, but have relatively large amounts of data to store in it (for example long strings
         containing lots of HTML or XML output) and do not want to waste expensive RAM on
         it. The disk storage module also allows for some more advanced and elaborate hacks
         such as sharing the cache space between a CLI script that writes to the cache and a
         web application that reads from it – but those are tricky, and will not be discussed
         here.
    •    Memcache is a popular open-source distributed memory-based object caching
         system. It runs on an external daemon (sometimes on a cluster of servers) and is not
         PHP-specific, but has an interface to PHP – the memcache extension, which is
         available as part of Zend Server. Memcache is external to PHP and hence is
         inherently slower than the other caching methods mentioned, but is very efficient when
         there is a need to share data between several machines in a cluster, and have it
         accurately synchronized.
    •    PHP Code based Caching is a method of caching data through code generation.
         Essentially, this means that instead of storing an array in cache, your code will create
         a PHP script containing the array and simply include it in order to read from the cache.
         This methodology is not common and has its downsides – namely that it might expose
         some security vulnerabilities because it actually executes PHP code stored in files
         written by the web server. However, when working with large arrays of objects that
         rarely change (for example a long list of countries and states), it is probably faster than
         the other methods mentioned, especially when the PHP code is cached by Optimizer+
         or another byte-code caching system.
While we will only going to cover Zend Data Cache in this whitepaper, you should be aware of
the other methods, and pick and choose between them. A single application can, and usually
should, combine different caching methodologies for different types of data. Abstraction
layers, such as Zend Framework's Zend_Cache component, can be used to easily switch
between cache storage systems.



How long do I need to cache for?
Setting the lifetime of each item in the cache mostly depends on your application's needs. The
rule of thumb is that you want to keep an item in cache as much as possible, but not more
than that. Consider how often the data is likely to change, and if it changes, how important it is
for you to show real-time data. As an example, an application displaying stock market quotes
should probably be as real-time as possible, to the extent of not caching anything. On the
other hand, caching the weather forecast for 30 minutes (or even for two weeks if you're
showing the weather for the Sahara) is probably reasonable.
Another thing to consider is the efficiency of the caching system you are using, and the size of
the data. Caching large data items for very short periods of time might become inefficient.
Almost all caching methods need to serialize the data before writing it to cache, and
unserialize it when reading. This process is somewhat expensive, and it becomes more




© Zend Technologies, Inc.                                                                              7
White Paper | A Practical Guide to Data Caching with Zend Server


expensive with large, complex data structures such as arrays or objects. Caching a 10,000
member array for a single second is probably a waste of resources.

Programmatic Cache Invalidation
By now you might be thinking “Ok, this is all fine – but sometimes, I can't always know in
advance when the data is going to change..!” - well, you are obviously right. Lifetime-based
cache expiry is good for “read-only” sort of websites, where the data is periodically updated by
the site's maintainer or by some predictable system. But all the buzz these days is about the
“read/write” web, where users can contribute content whenever they want. How do you go on
caching something like that? How would you cache, let's say, the comments posted on an
article in our imaginary blog?
Once approach is to cache for short periods of time – say 10 seconds. But this has a couple of
downsides: On one hand, you still need to hit the database frequently, even when there is no
real reason to. On the other hand, a user might post a comment and if it does not show up
immediately (but only after the user refreshed the page 8 times in 5 seconds) they'll probably
assume your site is broken, and post again, or just leave.
But there's a better way: Zend Data Cache allows you to use the API in order to invalidate the
cache when required. Let's go back to our imaginary blog, and take a look at the function
which is used to fetch a particular post's comments:


 1. function fetchComments($post) {
               fetchComments($post)
 2.   // Try to fetch from the cache first
 3.                 zend_shm_cache_fetch("comments-{$post}");
      $comments = zend_shm_cache_fetch("comments-{$post}");
 4.
 5.       ($comments       null)
      if ($comments === null) {
 6.     // Get the PDO adapter for the DB
 7.                    myBlogDb::getPdoAdapter();
                                ::getPdoAdapter
        $dbAdapter = myBlogDb::getPdoAdapter();
 8.
 9.     // Build the query
10.
10.     $query = "SELECT author, email, text, pubdate" .
11.
11.                                                         pubdate";
                   " FROM comments WHERE post = ? ORDER BY pubdate";
12.
12.                       $dbAdapter- prepare($query);
        $dbStatement = $dbAdapter->prepare($query);
13.
13.
14.
14.     // Execute the query
15.
15.     $comments = array();
16.
16.          ($dbStatement execute(array($post)))
              $dbStatement-         (array($post
        if ($dbStatement->execute(array($post))) {
17.
17.        while($comment     $dbStatement- fetch(PDO::FETCH_ASSOC)){
                                                     ::FETCH_ASSOC
           while($comment = $dbStatement->fetch(PDO::FETCH_ASSOC)){
18.
18.           $comments[]    $comment;
              $comments[] = $comment;
19.
19.        }
20.
20.
21.
21.        // Store the results in cache
22.
22.        zend_shm_cache_store("comments-{$post}", $comments,
           zend_shm_cache_store("comments-{$post}", $comments,
23.
23.                3600);
              24 * 3600);
24.
24.     }
25.
25.   }
26.
27.
27.            $comments;
      return $comments;
28.
28. }




© Zend Technologies, Inc.                                                                          8
White Paper | A Practical Guide to Data Caching with Zend Server


As you can see, the code already utilizes the caching functions, and caches the comments of
each post for 24 hours. But what if someone posts a new comment? Will they need to wait for
tomorrow before being able to see their new comment?
This is where cache invalidation comes into play. This technique is allowed through the
zend_shm_cache_delete() (or zend_disk_cache_delete() functions). All we need to do is make
sure to invalidate the cached comments for a post when a new comment is posted. Then, on
the next request to the page, a “live” list of comments will be presented and stored in the
cache, including the newly posted comment. The following code shows an what the comment
posting function will look like with this method applied:


 1. function postComment($post, $author, $email, $text)
             postComment($post, $author, $email, $text)
 2. {
 3.   // Get the PDO adapter for the DB
 4.                myBlogDb::getPdoAdapter();
                           ::getPdoAdapter
      $dbAdapter = myBlogDb::getPdoAdapter();
 5.
 6.   // Build the query
 7.   $query = "INSERT INTO " .
 8.                              author
                                     or,
               " comments(post, author, mail, text, date)" .
 9.                             :author
                                     or,                :date)";
               " VALUES(:post, :author, :mail, :text, :date)";
10.
10.
11.
11.                  $dbAdapter- prepare($query);
      $dbStatement = $dbAdapter->prepare($query);
12.
12.   $dbStatement- execute(array(
      $dbStatement->execute(array(
13.
13.     'post'      $post,
                 => $post,
14.
14.     'author
             or'    $author,
        'author' => $author,
15.
15.     'mail'      $email,
                 => $email,
16.
16.     'text'      $text,
                 => $text,
17.
17.     'date'      $_SERVER['REQUEST_TIME']
                 => $_SERVER['REQUEST_TIME']
18.
18.   ));
19.
19.
20.
20.   zend_shm_cache_delete("comments-{$post}");
      zend_shm_cache_delete("comments-{$post}");
21.
21. }


Notice line 19: all we had to do here is explicitly delete the cached comments for this post, and
this makes sure that whenever a new comment is saved in the DB, it will also appear in our
blog.
Zend Data Cache also allows you to                clear   out   all   cached   items   by   calling
zend_shm_cache_clear() with no parameters.




© Zend Technologies, Inc.                                                                             9
White Paper | A Practical Guide to Data Caching with Zend Server



Cache Namespacing
As you apply more and more caching to your application, making sure you expire all the
relevant items before new content is posted becomes a hassle. For example – in our blog
application, we have several places where the list of posts can appear – one is of course in the
blog's front page, but we also have the list of recent posts in our sidebar, and the same list of
posts as in the front page served as an XML feed, in both RSS and Atom formats. So that
might end up to be 3 or 4 different items that we must invalidate whenever a new post is
made. In some applications, you might need to invalidate dozens or even hundreds of items at
the same time.
Fortunately, Zend Data Cache makes it all easier by enabling you to namespace cache items.
Cache Namespacing (unrelated to the upcoming PHP 5.3 feature) allows you to group
different cache items together, and then easily invalidate all of them with one function call.
In order to group all post-listing related cache items together, we just need to add the
namespace as a prefix to the cache keys, followed by a double-colon (“::”) and the key itself,
like so:


 1. $recent = zend_shm_cache_fetch("postlist::recent-{$count}");
              zend_shm_cache_fetch( postlist::recent {$count}");
                                        list::recent-


The example above modifies our getRecentPosts() function to use the “postlisting” namespace
for when caching the recent post listing (of course, we will need to modify the store() calls in
accordance).
With all post-listing related cache items namespaced together, we simply need to call
zend_shm_cache_clear() with the namespace we want to clear as a parameter, like so:


 1. zend_shm_cache_clear("postlist");
    zend_shm_cache_clear("postlist");


This will invalidate and subsequently force regeneration of all the items stored under the
“postlisting” namespace in our shared memory cache. Note that calling
zend_shm_cache_clear() without passing a namespace will invalidate the entire cache.




© Zend Technologies, Inc.                                                                           10
White Paper | A Practical Guide to Data Caching with Zend Server


               Summary
               In this tutorial, we covered the different functions provided by Zend Data Cache, and
               demonstrated how to use them in order to store, fetch and delete items from the cache. We
               also covered cache namespacing, and how the API can be used to easily clear entire cache
               namespaces or all cached items with a single function call.
               Additionally, we overviewed the various considerations when creating a caching strategy -
               what to cache, how to cache it and for how long, and the pros and cons of different cache
               storage methods.
               Hopefully, this information will be enough to get you started with Zend Data Cache.



               Where Next?
               If you are interested in learning more about the Zend Server Data Cache API, you can read
               more in the relevant chapters in the Zend Server User Guide.
               You can learn more about Zend Server at http://www.zend.com/products/server
               If you have questions, you are welcome to post them on the Zend Server forum at
               http://forums.zend.com




Corporate Headquarters: Zend Technologies, Inc. 19200 Stevens Creek Blvd. Cupertino, CA 95014, USA · Tel +1-408-253-8800 · Fax +1-408-253-8801
Central Europe: (Germany, Austria, Switzerland) Zend Technologies GmbH Bayerstrasse 83, 80335 Munich, Germany · Tel +49-89-516199-0 · Fax +49-89-516199-20
International: Zend Technologies Ltd. 12 Abba Hillel Street, Ramat Gan, Israel 52506 · Tel +972-3-753-9500 · Fax +972-3-613-9671
France: Zend Technologies SARL, 5 Rue de Rome, ZAC de Nanteuil, 93110 Rosny-sous-Bois, France · Tel +33 1 4855 0200 · Fax +33 1 4812 3132
Italy: Zend Technologies, Largo Richini 6, 20122 Milano, Italy · Tel +39 02 5821 5832 · Fax +39 02 5821 5400

© 2009 Zend Corporation. Zend is a registered trademark of Zend Technologies Ltd.
All other trademarks are the property of their respective owners.   www.zend.com

0106-T-WP-R1-EN




               © Zend Technologies, Inc.                                                                                                               11

More Related Content

What's hot

Nuvola: a tale of migration to AWS
Nuvola: a tale of migration to AWSNuvola: a tale of migration to AWS
Nuvola: a tale of migration to AWSMatteo Moretti
 
Background Tasks in Node - Evan Tahler, TaskRabbit
Background Tasks in Node - Evan Tahler, TaskRabbitBackground Tasks in Node - Evan Tahler, TaskRabbit
Background Tasks in Node - Evan Tahler, TaskRabbitRedis Labs
 
MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用iammutex
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcachedJurriaan Persyn
 
ACADGILD:: HADOOP LESSON
ACADGILD:: HADOOP LESSON ACADGILD:: HADOOP LESSON
ACADGILD:: HADOOP LESSON Padma shree. T
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performanceguest9912e5
 
Evolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best PracticesEvolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best PracticesMydbops
 
Fluentd and Embulk Game Server 4
Fluentd and Embulk Game Server 4Fluentd and Embulk Game Server 4
Fluentd and Embulk Game Server 4N Masahiro
 
Pgbr 2013 postgres on aws
Pgbr 2013   postgres on awsPgbr 2013   postgres on aws
Pgbr 2013 postgres on awsEmanuel Calvo
 
Dbvisit replicate: logical replication made easy
Dbvisit replicate: logical replication made easyDbvisit replicate: logical replication made easy
Dbvisit replicate: logical replication made easyFranck Pachot
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerelliando dias
 
Writing A Foreign Data Wrapper
Writing A Foreign Data WrapperWriting A Foreign Data Wrapper
Writing A Foreign Data Wrapperpsoo1978
 
PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013Andrew Dunstan
 
Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1medcl
 
10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators  10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators iammutex
 
Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014Özgür Umut Vurgun
 
REDIS intro and how to use redis
REDIS intro and how to use redisREDIS intro and how to use redis
REDIS intro and how to use redisKris Jeong
 
Boost your website by running PHP on Nginx
Boost your website by running PHP on NginxBoost your website by running PHP on Nginx
Boost your website by running PHP on NginxHarald Zeitlhofer
 
Advanced Apache Cassandra Operations with JMX
Advanced Apache Cassandra Operations with JMXAdvanced Apache Cassandra Operations with JMX
Advanced Apache Cassandra Operations with JMXzznate
 

What's hot (20)

Nuvola: a tale of migration to AWS
Nuvola: a tale of migration to AWSNuvola: a tale of migration to AWS
Nuvola: a tale of migration to AWS
 
Background Tasks in Node - Evan Tahler, TaskRabbit
Background Tasks in Node - Evan Tahler, TaskRabbitBackground Tasks in Node - Evan Tahler, TaskRabbit
Background Tasks in Node - Evan Tahler, TaskRabbit
 
MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
ACADGILD:: HADOOP LESSON
ACADGILD:: HADOOP LESSON ACADGILD:: HADOOP LESSON
ACADGILD:: HADOOP LESSON
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance
 
Mongodb replication
Mongodb replicationMongodb replication
Mongodb replication
 
Evolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best PracticesEvolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best Practices
 
Fluentd and Embulk Game Server 4
Fluentd and Embulk Game Server 4Fluentd and Embulk Game Server 4
Fluentd and Embulk Game Server 4
 
Pgbr 2013 postgres on aws
Pgbr 2013   postgres on awsPgbr 2013   postgres on aws
Pgbr 2013 postgres on aws
 
Dbvisit replicate: logical replication made easy
Dbvisit replicate: logical replication made easyDbvisit replicate: logical replication made easy
Dbvisit replicate: logical replication made easy
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancer
 
Writing A Foreign Data Wrapper
Writing A Foreign Data WrapperWriting A Foreign Data Wrapper
Writing A Foreign Data Wrapper
 
PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013
 
Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1
 
10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators  10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators
 
Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014
 
REDIS intro and how to use redis
REDIS intro and how to use redisREDIS intro and how to use redis
REDIS intro and how to use redis
 
Boost your website by running PHP on Nginx
Boost your website by running PHP on NginxBoost your website by running PHP on Nginx
Boost your website by running PHP on Nginx
 
Advanced Apache Cassandra Operations with JMX
Advanced Apache Cassandra Operations with JMXAdvanced Apache Cassandra Operations with JMX
Advanced Apache Cassandra Operations with JMX
 

Viewers also liked

Nutricion y salud
 Nutricion y salud Nutricion y salud
Nutricion y saludSnike Golf
 
Clash of the Titans: Releasing the Kraken | NodeJS @paypal
Clash of the Titans: Releasing the Kraken | NodeJS @paypalClash of the Titans: Releasing the Kraken | NodeJS @paypal
Clash of the Titans: Releasing the Kraken | NodeJS @paypalBill Scott
 
Comunidades Informaticas
Comunidades InformaticasComunidades Informaticas
Comunidades Informaticasguest44c5e8
 
Day con-lam-giau-tap-13
Day con-lam-giau-tap-13Day con-lam-giau-tap-13
Day con-lam-giau-tap-13Hung Duong
 
Dust control in industrial operations
Dust control in industrial operations Dust control in industrial operations
Dust control in industrial operations pule soga
 
Servitalent: Presentación corporativa 2014
Servitalent: Presentación corporativa 2014Servitalent: Presentación corporativa 2014
Servitalent: Presentación corporativa 2014Servitalent
 
Recuperacion de datos despues de formatear en linux
Recuperacion de datos despues de formatear en linuxRecuperacion de datos despues de formatear en linux
Recuperacion de datos despues de formatear en linuxoverdrai
 
Prideology: The Study of Pride
Prideology: The Study of PridePrideology: The Study of Pride
Prideology: The Study of PrideBottomology
 
Презентация Nanoplus(ru)
Презентация Nanoplus(ru)Презентация Nanoplus(ru)
Презентация Nanoplus(ru)nano corporation
 
CR design Portfolio
CR design PortfolioCR design Portfolio
CR design Portfoliocrdesignusa
 
Folleto StoneWork Solutions _ Castellano
Folleto StoneWork Solutions _ CastellanoFolleto StoneWork Solutions _ Castellano
Folleto StoneWork Solutions _ Castellanooscar_garcia_arano
 
Richmond Review - Richmond man gets a new leash on life
Richmond Review - Richmond man gets a new leash on lifeRichmond Review - Richmond man gets a new leash on life
Richmond Review - Richmond man gets a new leash on lifeErin Anne Beirne, MAPC
 
Ofertas de empleo albacete trabajo albacete. boletín nº 66 mica_consultores
Ofertas de empleo albacete trabajo albacete. boletín nº 66 mica_consultoresOfertas de empleo albacete trabajo albacete. boletín nº 66 mica_consultores
Ofertas de empleo albacete trabajo albacete. boletín nº 66 mica_consultoresMICA CONSULTORES
 
Clusterin, nuevo marcador tumoral - Agosto 2013
Clusterin, nuevo marcador tumoral - Agosto 2013Clusterin, nuevo marcador tumoral - Agosto 2013
Clusterin, nuevo marcador tumoral - Agosto 2013Santi Zappa
 

Viewers also liked (20)

Nutricion y salud
 Nutricion y salud Nutricion y salud
Nutricion y salud
 
K229
K229K229
K229
 
Clash of the Titans: Releasing the Kraken | NodeJS @paypal
Clash of the Titans: Releasing the Kraken | NodeJS @paypalClash of the Titans: Releasing the Kraken | NodeJS @paypal
Clash of the Titans: Releasing the Kraken | NodeJS @paypal
 
Ciao Bambino! Family Travel in China
Ciao Bambino! Family Travel in ChinaCiao Bambino! Family Travel in China
Ciao Bambino! Family Travel in China
 
Machinists Handbook
Machinists   HandbookMachinists   Handbook
Machinists Handbook
 
Comunidades Informaticas
Comunidades InformaticasComunidades Informaticas
Comunidades Informaticas
 
Day con-lam-giau-tap-13
Day con-lam-giau-tap-13Day con-lam-giau-tap-13
Day con-lam-giau-tap-13
 
Dust control in industrial operations
Dust control in industrial operations Dust control in industrial operations
Dust control in industrial operations
 
Servitalent: Presentación corporativa 2014
Servitalent: Presentación corporativa 2014Servitalent: Presentación corporativa 2014
Servitalent: Presentación corporativa 2014
 
Recuperacion de datos despues de formatear en linux
Recuperacion de datos despues de formatear en linuxRecuperacion de datos despues de formatear en linux
Recuperacion de datos despues de formatear en linux
 
Carta del Papa Francisco al Carmelo Teresiano
Carta del Papa Francisco al Carmelo TeresianoCarta del Papa Francisco al Carmelo Teresiano
Carta del Papa Francisco al Carmelo Teresiano
 
Prideology: The Study of Pride
Prideology: The Study of PridePrideology: The Study of Pride
Prideology: The Study of Pride
 
Oat time line
Oat time lineOat time line
Oat time line
 
Презентация Nanoplus(ru)
Презентация Nanoplus(ru)Презентация Nanoplus(ru)
Презентация Nanoplus(ru)
 
CR design Portfolio
CR design PortfolioCR design Portfolio
CR design Portfolio
 
Folleto StoneWork Solutions _ Castellano
Folleto StoneWork Solutions _ CastellanoFolleto StoneWork Solutions _ Castellano
Folleto StoneWork Solutions _ Castellano
 
Richmond Review - Richmond man gets a new leash on life
Richmond Review - Richmond man gets a new leash on lifeRichmond Review - Richmond man gets a new leash on life
Richmond Review - Richmond man gets a new leash on life
 
Mountaineer 2013 05-31
Mountaineer 2013 05-31Mountaineer 2013 05-31
Mountaineer 2013 05-31
 
Ofertas de empleo albacete trabajo albacete. boletín nº 66 mica_consultores
Ofertas de empleo albacete trabajo albacete. boletín nº 66 mica_consultoresOfertas de empleo albacete trabajo albacete. boletín nº 66 mica_consultores
Ofertas de empleo albacete trabajo albacete. boletín nº 66 mica_consultores
 
Clusterin, nuevo marcador tumoral - Agosto 2013
Clusterin, nuevo marcador tumoral - Agosto 2013Clusterin, nuevo marcador tumoral - Agosto 2013
Clusterin, nuevo marcador tumoral - Agosto 2013
 

Similar to Zend Server Data Caching

Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and ScalabilityMediacurrent
 
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 scalabilityWim Godden
 
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 2012Wim Godden
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetAchieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetAchieve Internet
 
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 scalabilityWim Godden
 
Caching objects-in-memory
Caching objects-in-memoryCaching objects-in-memory
Caching objects-in-memoryMauro Cassani
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariJoseph Scott
 
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 @ PHPTourWim 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 scalabilityWim Godden
 
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 2011Wim Godden
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APCBen Ramsey
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend frameworkAlan Seiden
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalabilityTwinbit
 
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 2011Wim Godden
 
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 applicationsEnrico Zimuel
 
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 scalabilityWim Godden
 
Dutch php conference_apc_mem2010
Dutch php conference_apc_mem2010Dutch php conference_apc_mem2010
Dutch php conference_apc_mem2010isnull
 

Similar to Zend Server Data Caching (20)

Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and 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
 
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
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
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 objects-in-memory
Caching objects-in-memoryCaching objects-in-memory
Caching objects-in-memory
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
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
 
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 @ 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 with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
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
 
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
 
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
 
Dutch php conference_apc_mem2010
Dutch php conference_apc_mem2010Dutch php conference_apc_mem2010
Dutch php conference_apc_mem2010
 
Caching
CachingCaching
Caching
 

More from El Taller Web

Z-Ray en Zend Server 8
Z-Ray en Zend Server 8Z-Ray en Zend Server 8
Z-Ray en Zend Server 8El Taller Web
 
Webinario mejorando el desempeño con zend server
Webinario   mejorando el desempeño con zend serverWebinario   mejorando el desempeño con zend server
Webinario mejorando el desempeño con zend serverEl Taller Web
 
Patrones de diseño en POO
Patrones de diseño en POOPatrones de diseño en POO
Patrones de diseño en POOEl Taller Web
 
Zend Framework 2 y MongoDB
Zend Framework 2 y  MongoDBZend Framework 2 y  MongoDB
Zend Framework 2 y MongoDBEl Taller Web
 
Zend/Cache de Zend Framework 2
Zend/Cache de Zend Framework 2Zend/Cache de Zend Framework 2
Zend/Cache de Zend Framework 2El Taller Web
 
Módulos en Zend Framework 2
Módulos en Zend Framework 2Módulos en Zend Framework 2
Módulos en Zend Framework 2El Taller Web
 
Servicios en Zend Framework 2
Servicios en  Zend Framework 2Servicios en  Zend Framework 2
Servicios en Zend Framework 2El Taller Web
 
Mongo db enterprise_datasheet
Mongo db enterprise_datasheetMongo db enterprise_datasheet
Mongo db enterprise_datasheetEl Taller Web
 
10gen telco white_paper
10gen telco white_paper10gen telco white_paper
10gen telco white_paperEl Taller Web
 
Cisco web ex-cs-0511-final
Cisco web ex-cs-0511-finalCisco web ex-cs-0511-final
Cisco web ex-cs-0511-finalEl Taller Web
 
Replica Sets en MongoDB
Replica Sets en MongoDBReplica Sets en MongoDB
Replica Sets en MongoDBEl Taller Web
 
Introducción a Zend Framework 2
Introducción a  Zend Framework 2Introducción a  Zend Framework 2
Introducción a Zend Framework 2El Taller Web
 
Introducción a PHP 5.4
Introducción a PHP 5.4Introducción a PHP 5.4
Introducción a PHP 5.4El Taller Web
 
TCO Comparison MongoDB & Oracle
TCO Comparison MongoDB & OracleTCO Comparison MongoDB & Oracle
TCO Comparison MongoDB & OracleEl Taller Web
 
Webinario Operaciones Básicas MongoDB
Webinario Operaciones Básicas MongoDBWebinario Operaciones Básicas MongoDB
Webinario Operaciones Básicas MongoDBEl Taller Web
 
Información sobre la certificación Zend
Información sobre la certificación Zend Información sobre la certificación Zend
Información sobre la certificación Zend El Taller Web
 

More from El Taller Web (18)

Z-Ray en Zend Server 8
Z-Ray en Zend Server 8Z-Ray en Zend Server 8
Z-Ray en Zend Server 8
 
Webinario mejorando el desempeño con zend server
Webinario   mejorando el desempeño con zend serverWebinario   mejorando el desempeño con zend server
Webinario mejorando el desempeño con zend server
 
Patrones de diseño en POO
Patrones de diseño en POOPatrones de diseño en POO
Patrones de diseño en POO
 
Memcached y PHP
Memcached y PHPMemcached y PHP
Memcached y PHP
 
Zend Framework 2 y MongoDB
Zend Framework 2 y  MongoDBZend Framework 2 y  MongoDB
Zend Framework 2 y MongoDB
 
Zend/Cache de Zend Framework 2
Zend/Cache de Zend Framework 2Zend/Cache de Zend Framework 2
Zend/Cache de Zend Framework 2
 
Módulos en Zend Framework 2
Módulos en Zend Framework 2Módulos en Zend Framework 2
Módulos en Zend Framework 2
 
Servicios en Zend Framework 2
Servicios en  Zend Framework 2Servicios en  Zend Framework 2
Servicios en Zend Framework 2
 
Offers
OffersOffers
Offers
 
Mongo db enterprise_datasheet
Mongo db enterprise_datasheetMongo db enterprise_datasheet
Mongo db enterprise_datasheet
 
10gen telco white_paper
10gen telco white_paper10gen telco white_paper
10gen telco white_paper
 
Cisco web ex-cs-0511-final
Cisco web ex-cs-0511-finalCisco web ex-cs-0511-final
Cisco web ex-cs-0511-final
 
Replica Sets en MongoDB
Replica Sets en MongoDBReplica Sets en MongoDB
Replica Sets en MongoDB
 
Introducción a Zend Framework 2
Introducción a  Zend Framework 2Introducción a  Zend Framework 2
Introducción a Zend Framework 2
 
Introducción a PHP 5.4
Introducción a PHP 5.4Introducción a PHP 5.4
Introducción a PHP 5.4
 
TCO Comparison MongoDB & Oracle
TCO Comparison MongoDB & OracleTCO Comparison MongoDB & Oracle
TCO Comparison MongoDB & Oracle
 
Webinario Operaciones Básicas MongoDB
Webinario Operaciones Básicas MongoDBWebinario Operaciones Básicas MongoDB
Webinario Operaciones Básicas MongoDB
 
Información sobre la certificación Zend
Información sobre la certificación Zend Información sobre la certificación Zend
Información sobre la certificación Zend
 

Recently uploaded

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Zend Server Data Caching

  • 1. White Paper: A Practical Guide to Data Caching with Zend Server By Shahar Evron, Product Manager, Zend Technologies, Inc. Technical April 2009 © 2009 Zend Technologies, Inc. All rights reserved.
  • 2. White Paper | A Practical Guide to Data Caching with Zend Server Table of Contents Introduction 3 Ok, how do I get started? 4 But wait... 6 How do I decide what to cache, and how? 6 What do I cache? 6 How do I cache? 6 How long do I need to cache for? 7 Programmatic Cache Invalidation 8 Cache Namespacing 10 Summary 11 Where Next? 11 © Zend Technologies, Inc. 2
  • 3. White Paper | A Practical Guide to Data Caching with Zend Server Introduction When asked about the most significant methods to speed up PHP applications, most experts would say “Cache, Cache and Cache”. There are a lot of optimizations that could be done to PHP code that would make it run faster, but the most effective method to speed up PHP execution is to simply execute less, and one of the best ways to achieve that is through caching. Zend Server provides several caching-related features, including Optimizer+ for byte-code caching, full-page caching using Zend Page Cache, and the Data Cache API. To avoid confusion, let's go over them quickly: • Zend Optimizer+ performs byte-code optimization and caching. This speeds up PHP applications by eliminating the process of reading scripts from disk and compiling them, often resulting in a speedup of x2 – x3 times, depending on the application. Zend Optimizer+ runs automatically, and installing your application on top of Zend Server is all you need to do in order to enjoy its benefits. • Zend Page Cache allows caching of entire PHP web pages, or more correctly put, entire HTTP responses sent out from PHP. Page Caching permits dramatically improving the performance of pages on web applications (sometimes running as high as 10x, 20x and even 100x times faster), while maintaining dynamic capabilities through an elaborate system of caching rules that could be based on request parameters and user session data. Page Caching also has the benefit of not requiring any code changes, and can be set up from the Zend Server UI. • Zend Data Cache is a set of API functions enabling a developer to store and manage data items (PHP strings, arrays and other data) and even output elements in either disk-based cache or shared memory cache. Zend Data Cache allows for precision- guided caching when Page Caching is not an option. The provided API is easy-to-use on existing code, and in many cases a developer can skip existing code sections by simply wrapping them with caching APIs. This whitepaper will demonstrate how to use the Zend Data Cache API in order to speed up a typical PHP application. © Zend Technologies, Inc. 3
  • 4. White Paper | A Practical Guide to Data Caching with Zend Server Ok, how do I get started? Getting started with Zend Data Cache is extremely easy: The first functions you need to know about are zend_shm_cache_fetch() and zend_shm_cache_store(). These two functions are used for storing data in the shared-memory cache, and for fetching data from the cache. Note: Zend Data Cache offers two storage modules: The shared memory (“shm”) module, and the disk module. We will revisit the differences later on, but for now, you should know that all functions mentioned here with the 'zend_shm' prefix are used for shared memory storage. For each function mentioned, there is an exact twin with the 'zend_disk' prefix that preforms the same actions for the disk-based cache. For the two functions mentioned above, there are the zend_disk_cache_store() and zend_disk_cache_fetch() twin functions. For convenience, we will only mention the shared memory functions here – but keep in mind that you can (and should, in some situations) use the disk-based cache functions as well. Since code speaks louder than words, consider the following piece of code taken from an imaginary but typical blogging platform: 1. function getRecentPosts($count = 5) { getRecentPosts( 2. // Get the PDO adapter for the DB 3. myBlogDb::getPdoAdapter(); ::getPdoAdapter $dbAdapter = myBlogDb::getPdoAdapter(); 4. 5. // Build the query 6. $query = "SELECT title, author, pubdate FROM posts" . 7. ?"; " ORDER BY pubdate DESC LIMIT ?"; 8. $dbAdapter- prepare($query); $dbStatement = $dbAdapter->prepare($query); 9. 10. 10. // Execute the query and put data into an array 11. 11. $recentPosts = array(); 12. ($dbStatement execute(array($count))) $dbStatement- (array($count if ($dbStatement->execute(array($count))) { 13. while($post $dbStatement- fetch(PDO::FETCH_ASSOC)) ::FETCH_ASSOC while($post = $dbStatement->fetch(PDO::FETCH_ASSOC)) { 14. $recentPosts[] = $post; $recentPosts[] $post; 15. 15. } 16. } 17. 18. 18. $recentPosts; return $recentPosts; 19. 19. } This function is used to fetch an array of the most recent posts in our blog, and will fetch the title, author and publication date for each one. This is done by running an SQL query and placing the results into an array. While the list of recent posts in a blog is dynamic, it is rarely changing (“rarely” is of course a relative term – but even in a very busy blog, you are likely to get hundreds or thousands of “reads” for each new post). This makes it a very good candidate for caching, it and should be fairly easy to do: 1. function getRecentPosts($count = 5) { getRecentPosts( 2. // Try to fetch from the cache first 3. zend_shm_cache_fetch('recentposts'); $recentPosts = zend_shm_cache_fetch('recentposts'); 4. 5. ($recentPosts null) if ($recentPosts === null) { 6. // Get the PDO adapter for the DB 7. myBlogDb::getPdoAdapter(); ::getPdoAdapter $dbAdapter = myBlogDb::getPdoAdapter(); © Zend Technologies, Inc. 4
  • 5. White Paper | A Practical Guide to Data Caching with Zend Server 8. 9. // Build the query 10. 10. $query = "SELECT title, author, pubdate FROM posts" . 11. 11. ?"; " ORDER BY pubdate DESC LIMIT ?"; 12. 12. $dbAdapter- prepare($query); $dbStatement = $dbAdapter->prepare($query); 13. 13. 14. 14. // Execute the query 15. 15. $recentPosts = array(); 16. 16. ($dbStatement execute(array($count))) $dbStatement- (array($count if ($dbStatement->execute(array($count))) { 17. 17. while($post $dbStatement- fetch(PDO::FETCH_ASSOC)) ::FETCH_ASSOC while($post = $dbStatement->fetch(PDO::FETCH_ASSOC)) { 18. 18. $recentPosts[] $post; $recentPosts[] = $post; 19. 19. } 20. 20. 21. 21. // Store the results in cache 22. 22. zend_shm_cache_store('recentposts', $recentPosts, zend_shm_cache_store('recentposts', $recentPosts, 23. 23. 3600); 24 * 3600); 24. 24. } 25. 25. } 26. 27. 27. $recentPosts; return $recentPosts; 28. 28. } What has changed? We added three lines of code (not including blank lines and comments...) and here is what we get: • First, we try to fetch the list of recent posts from our shared memory cache. The list of recent posts is stored under a unique key – 'recentposts', which is passed as a parameter to the fetch() function (line 4). • If the item does not exist, or is “stale” (in caching terms that means it has passed its expiry date), the function will return NULL. This allows us to check if valid data was returned from the cache (line 6). If the return value is NULL (note the triple-equal operator! this makes sure that we did not get an empty array, which might be a valid cached value in this case), we fetch the live data from our DB, as we did before. • After fetching live data from the DB, we make sure to store it in our cache, under the 'recentposts' key, for 24 hours (line 24). We only do this if the query was successfully executed. • Whether the data came from the DB or from our cache, we return it as we always did. The function's signature did not change, and we do not need to modify other parts of the code. This allows us to skip most of the code responsible for fetching the list of recent posts from the DB, and only execute it once a day or so. This might seem like a small victory, but remember that database queries are one of the biggest hurdles in the road for scalability and performance. Each reduced query is a win. © Zend Technologies, Inc. 5
  • 6. White Paper | A Practical Guide to Data Caching with Zend Server But wait... Some of you have probably noticed, that our function takes an argument, and might return different results depending on that argument. Ignoring this when caching the results might result in unexpected data being returned. This can be easily solved by using the $count parameter as part of the cache item key, like so: 29. 29. $recentPosts = zend_shm_cache_fetch("recentposts-{$count}"); zend_shm_cache_fetch("recentposts-{$count}"); Of course, you will need to make the same change in line 24 when storing the data. Now, we will end up with different cached item for different values of the $count parameter. If we use the same function to show the last 5 posts in the home page, but have a special page listing the last 20 posts, they will both show the correct data. How do I decide what to cache, and how? See, that was simple. But the real trick when caching is not using the API – it's actually deciding what to cache, using what storage method, and for how long. What do I cache? Deciding what to cache is probably once of the places where inexperienced developers go wrong. After all, “premature optimization is the root of all evil”, and it's a pretty common evil too. Many developers tend to spend hours optimizing pieces of code which they think might be problematic, but in reality account for 0.02% of the application's execution time. The smartest approach to caching would be to look for the slowest spots in your application, and the best way to do that would be to use a combination of performance monitoring and profiling tools – such as Zend Server's Monitor combined with Zend Studio's Profiler. You can use those to detect the real bottlenecks in your application, and then proceed to eradicate them by applying one of the possible caching techniques. It is usually also very useful to use a benchmarking tool such as ab, siege or jMeter in order to quantify the effect of any optimization you make – but take notice that sometimes under heavy production load, the effect is way bigger than any synthetic benchmark might imply. Another point you should keep in mind is that a 10% speedup on a page which accounts for 80% of your traffic (such as the home page on some applications) is usually way more effective than a 70% speedup on a page which accounts for 2% of your traffic. You should almost always start with the most popular parts of your application. How do I cache? Zend Server offers three caching methods: Page Cache, and two Data Cache storage modules. Additionally, several other caching techniques are available out there (and as part of Zend Server), such as memcache-based clustered cache and even PHP code generation based caching. Each one of those techniques has its pros and cons, and while we will not cover all of them in details here, let's do a quick overview of them: • Zend Page Cache should be preferred if possible – being almost always the fastest of them all. Zend Server's Page Cache feature is quite flexible, but unfortunately, in some cases caching entire pages becomes inefficient – for example when a page's © Zend Technologies, Inc. 6
  • 7. White Paper | A Practical Guide to Data Caching with Zend Server content relies on too many factors and changes constantly, or when a change cannot be predicted based on request or session parameters. • Zend Data Cache Shared Memory Storage should be the preferred method of caching small data items or pieces of output. It stores the data in a block of RAM on your server, which is shared by all the different PHP processes (be it Apache processes or FastCGI processes) and hence its name. This makes it very fast, but somewhat size limited; however, unless you're storing huge amounts of data in cache, you should have no problems. • Zend Data Cache Disk Storage should be used when you need a relatively fast local cache, but have relatively large amounts of data to store in it (for example long strings containing lots of HTML or XML output) and do not want to waste expensive RAM on it. The disk storage module also allows for some more advanced and elaborate hacks such as sharing the cache space between a CLI script that writes to the cache and a web application that reads from it – but those are tricky, and will not be discussed here. • Memcache is a popular open-source distributed memory-based object caching system. It runs on an external daemon (sometimes on a cluster of servers) and is not PHP-specific, but has an interface to PHP – the memcache extension, which is available as part of Zend Server. Memcache is external to PHP and hence is inherently slower than the other caching methods mentioned, but is very efficient when there is a need to share data between several machines in a cluster, and have it accurately synchronized. • PHP Code based Caching is a method of caching data through code generation. Essentially, this means that instead of storing an array in cache, your code will create a PHP script containing the array and simply include it in order to read from the cache. This methodology is not common and has its downsides – namely that it might expose some security vulnerabilities because it actually executes PHP code stored in files written by the web server. However, when working with large arrays of objects that rarely change (for example a long list of countries and states), it is probably faster than the other methods mentioned, especially when the PHP code is cached by Optimizer+ or another byte-code caching system. While we will only going to cover Zend Data Cache in this whitepaper, you should be aware of the other methods, and pick and choose between them. A single application can, and usually should, combine different caching methodologies for different types of data. Abstraction layers, such as Zend Framework's Zend_Cache component, can be used to easily switch between cache storage systems. How long do I need to cache for? Setting the lifetime of each item in the cache mostly depends on your application's needs. The rule of thumb is that you want to keep an item in cache as much as possible, but not more than that. Consider how often the data is likely to change, and if it changes, how important it is for you to show real-time data. As an example, an application displaying stock market quotes should probably be as real-time as possible, to the extent of not caching anything. On the other hand, caching the weather forecast for 30 minutes (or even for two weeks if you're showing the weather for the Sahara) is probably reasonable. Another thing to consider is the efficiency of the caching system you are using, and the size of the data. Caching large data items for very short periods of time might become inefficient. Almost all caching methods need to serialize the data before writing it to cache, and unserialize it when reading. This process is somewhat expensive, and it becomes more © Zend Technologies, Inc. 7
  • 8. White Paper | A Practical Guide to Data Caching with Zend Server expensive with large, complex data structures such as arrays or objects. Caching a 10,000 member array for a single second is probably a waste of resources. Programmatic Cache Invalidation By now you might be thinking “Ok, this is all fine – but sometimes, I can't always know in advance when the data is going to change..!” - well, you are obviously right. Lifetime-based cache expiry is good for “read-only” sort of websites, where the data is periodically updated by the site's maintainer or by some predictable system. But all the buzz these days is about the “read/write” web, where users can contribute content whenever they want. How do you go on caching something like that? How would you cache, let's say, the comments posted on an article in our imaginary blog? Once approach is to cache for short periods of time – say 10 seconds. But this has a couple of downsides: On one hand, you still need to hit the database frequently, even when there is no real reason to. On the other hand, a user might post a comment and if it does not show up immediately (but only after the user refreshed the page 8 times in 5 seconds) they'll probably assume your site is broken, and post again, or just leave. But there's a better way: Zend Data Cache allows you to use the API in order to invalidate the cache when required. Let's go back to our imaginary blog, and take a look at the function which is used to fetch a particular post's comments: 1. function fetchComments($post) { fetchComments($post) 2. // Try to fetch from the cache first 3. zend_shm_cache_fetch("comments-{$post}"); $comments = zend_shm_cache_fetch("comments-{$post}"); 4. 5. ($comments null) if ($comments === null) { 6. // Get the PDO adapter for the DB 7. myBlogDb::getPdoAdapter(); ::getPdoAdapter $dbAdapter = myBlogDb::getPdoAdapter(); 8. 9. // Build the query 10. 10. $query = "SELECT author, email, text, pubdate" . 11. 11. pubdate"; " FROM comments WHERE post = ? ORDER BY pubdate"; 12. 12. $dbAdapter- prepare($query); $dbStatement = $dbAdapter->prepare($query); 13. 13. 14. 14. // Execute the query 15. 15. $comments = array(); 16. 16. ($dbStatement execute(array($post))) $dbStatement- (array($post if ($dbStatement->execute(array($post))) { 17. 17. while($comment $dbStatement- fetch(PDO::FETCH_ASSOC)){ ::FETCH_ASSOC while($comment = $dbStatement->fetch(PDO::FETCH_ASSOC)){ 18. 18. $comments[] $comment; $comments[] = $comment; 19. 19. } 20. 20. 21. 21. // Store the results in cache 22. 22. zend_shm_cache_store("comments-{$post}", $comments, zend_shm_cache_store("comments-{$post}", $comments, 23. 23. 3600); 24 * 3600); 24. 24. } 25. 25. } 26. 27. 27. $comments; return $comments; 28. 28. } © Zend Technologies, Inc. 8
  • 9. White Paper | A Practical Guide to Data Caching with Zend Server As you can see, the code already utilizes the caching functions, and caches the comments of each post for 24 hours. But what if someone posts a new comment? Will they need to wait for tomorrow before being able to see their new comment? This is where cache invalidation comes into play. This technique is allowed through the zend_shm_cache_delete() (or zend_disk_cache_delete() functions). All we need to do is make sure to invalidate the cached comments for a post when a new comment is posted. Then, on the next request to the page, a “live” list of comments will be presented and stored in the cache, including the newly posted comment. The following code shows an what the comment posting function will look like with this method applied: 1. function postComment($post, $author, $email, $text) postComment($post, $author, $email, $text) 2. { 3. // Get the PDO adapter for the DB 4. myBlogDb::getPdoAdapter(); ::getPdoAdapter $dbAdapter = myBlogDb::getPdoAdapter(); 5. 6. // Build the query 7. $query = "INSERT INTO " . 8. author or, " comments(post, author, mail, text, date)" . 9. :author or, :date)"; " VALUES(:post, :author, :mail, :text, :date)"; 10. 10. 11. 11. $dbAdapter- prepare($query); $dbStatement = $dbAdapter->prepare($query); 12. 12. $dbStatement- execute(array( $dbStatement->execute(array( 13. 13. 'post' $post, => $post, 14. 14. 'author or' $author, 'author' => $author, 15. 15. 'mail' $email, => $email, 16. 16. 'text' $text, => $text, 17. 17. 'date' $_SERVER['REQUEST_TIME'] => $_SERVER['REQUEST_TIME'] 18. 18. )); 19. 19. 20. 20. zend_shm_cache_delete("comments-{$post}"); zend_shm_cache_delete("comments-{$post}"); 21. 21. } Notice line 19: all we had to do here is explicitly delete the cached comments for this post, and this makes sure that whenever a new comment is saved in the DB, it will also appear in our blog. Zend Data Cache also allows you to clear out all cached items by calling zend_shm_cache_clear() with no parameters. © Zend Technologies, Inc. 9
  • 10. White Paper | A Practical Guide to Data Caching with Zend Server Cache Namespacing As you apply more and more caching to your application, making sure you expire all the relevant items before new content is posted becomes a hassle. For example – in our blog application, we have several places where the list of posts can appear – one is of course in the blog's front page, but we also have the list of recent posts in our sidebar, and the same list of posts as in the front page served as an XML feed, in both RSS and Atom formats. So that might end up to be 3 or 4 different items that we must invalidate whenever a new post is made. In some applications, you might need to invalidate dozens or even hundreds of items at the same time. Fortunately, Zend Data Cache makes it all easier by enabling you to namespace cache items. Cache Namespacing (unrelated to the upcoming PHP 5.3 feature) allows you to group different cache items together, and then easily invalidate all of them with one function call. In order to group all post-listing related cache items together, we just need to add the namespace as a prefix to the cache keys, followed by a double-colon (“::”) and the key itself, like so: 1. $recent = zend_shm_cache_fetch("postlist::recent-{$count}"); zend_shm_cache_fetch( postlist::recent {$count}"); list::recent- The example above modifies our getRecentPosts() function to use the “postlisting” namespace for when caching the recent post listing (of course, we will need to modify the store() calls in accordance). With all post-listing related cache items namespaced together, we simply need to call zend_shm_cache_clear() with the namespace we want to clear as a parameter, like so: 1. zend_shm_cache_clear("postlist"); zend_shm_cache_clear("postlist"); This will invalidate and subsequently force regeneration of all the items stored under the “postlisting” namespace in our shared memory cache. Note that calling zend_shm_cache_clear() without passing a namespace will invalidate the entire cache. © Zend Technologies, Inc. 10
  • 11. White Paper | A Practical Guide to Data Caching with Zend Server Summary In this tutorial, we covered the different functions provided by Zend Data Cache, and demonstrated how to use them in order to store, fetch and delete items from the cache. We also covered cache namespacing, and how the API can be used to easily clear entire cache namespaces or all cached items with a single function call. Additionally, we overviewed the various considerations when creating a caching strategy - what to cache, how to cache it and for how long, and the pros and cons of different cache storage methods. Hopefully, this information will be enough to get you started with Zend Data Cache. Where Next? If you are interested in learning more about the Zend Server Data Cache API, you can read more in the relevant chapters in the Zend Server User Guide. You can learn more about Zend Server at http://www.zend.com/products/server If you have questions, you are welcome to post them on the Zend Server forum at http://forums.zend.com Corporate Headquarters: Zend Technologies, Inc. 19200 Stevens Creek Blvd. Cupertino, CA 95014, USA · Tel +1-408-253-8800 · Fax +1-408-253-8801 Central Europe: (Germany, Austria, Switzerland) Zend Technologies GmbH Bayerstrasse 83, 80335 Munich, Germany · Tel +49-89-516199-0 · Fax +49-89-516199-20 International: Zend Technologies Ltd. 12 Abba Hillel Street, Ramat Gan, Israel 52506 · Tel +972-3-753-9500 · Fax +972-3-613-9671 France: Zend Technologies SARL, 5 Rue de Rome, ZAC de Nanteuil, 93110 Rosny-sous-Bois, France · Tel +33 1 4855 0200 · Fax +33 1 4812 3132 Italy: Zend Technologies, Largo Richini 6, 20122 Milano, Italy · Tel +39 02 5821 5832 · Fax +39 02 5821 5400 © 2009 Zend Corporation. Zend is a registered trademark of Zend Technologies Ltd. All other trademarks are the property of their respective owners. www.zend.com 0106-T-WP-R1-EN © Zend Technologies, Inc. 11