Web Cache: APC vs Memcached vs Varnish

With increasing amounts of data and server-side processing, caching systems are as important as ever. There are so many varieties of these systems out there, it can be confusing if you don’t understanding the different nuances. Worse yet, if you pick the wrong caching system for your needs or fail to optimize it correctly, the results could be disastrous.

There are two broad types of cache when it comes to web sites and web applications. Client side, and server side.

Client side caching is what your web browser does. It saves the HTML and other content of a web page on your hard disk. This prevents you from repeatedly downloading the same resources from the server over and over again.

Server side caching is when the web server or web application saves these resources. This prevents the server from having to go through the processing required to build these documents. The rest of this article will be about different server side caching tools.

My goal in this article is to give you a basic overview of caching systems for web based applications, with a particular focus on PHP and Drupal. The 3 systems I’ll cover are APC, Memcached, and Varnish. I’ll also talk about Drupal’s application cache and how that can tie in with APC or Memcached. Let’s dive in.

Alternative PHP Cache (APC)

APC provides two caching mechanisms.

  1. APC caches the opcode generated during the PHP execution cycle and then later will be able to avoid loading and parsing PHP files repeatedly.
  2. APC also provides a key-value, object cache for PHP applications in shared memory.

The opcode cache can speed up PHP applications by as much as 3 times. We find it particularly helpful in speeding up Drupal. That’s because Drupal code is distributed over many different modules and consequently many different files. APC cuts down on the disk I/O by caching the bytecode from the PHP compiler. The next time these files are needed, they won’t have to be loaded from the disk or parsed by the PHP compiler. This is great but an important thing to keep in mind is that APC’s opcode cache only caches the PHP bytecode. It still has to execute that PHP, which will run database queries and build the HTML output.

The object cache simply allows your application to cache arbitrary pieces of data in shared memory and retrieve them later. For example, if you have to query some tables to build a data object, you can cache the data object with APC and fetch it later by a key that you define when you store it. You can then keep retrieving it from shared memory until it expires and then re-build and re-cache the data object.

Memcached

Memcached is a distributed, key-value, object cache in memory. This is similar to the object cache provided by APC but there are some important differences. It’s in-memory, while APC’s object cache is in shared memory. This will make Memcached faster, but will also require the memory allocation for it’s storage. The other major difference is that Memcached is distributed. This means that it runs across multiple servers. For example, if you’re load-balancing your application. Generally, the need for a distributed object cache is why you would use Memcached.

Websites we currently know of using Memcached:

  • Wikipedia
  • Flickr
  • Twitter
  • Youtube
  • Digg
  • WordPress.com
  • Craigslist

Varnish (Web Application Accelerator)

Varnish is a caching HTTP reverse proxy. The reverse proxy part means that it sits between your application and the outside world. Visiting your domain will actually connect to Varnish. Varnish will then make the corresponding request to your application and then deliver it to the client. It will cache the results of these requests based on a configuration file you can write in the Varnish Configuration Language.

Varnish is neither an opcode cache like APC’s opcode cache component, nor an object cache like those in APC or Memcached. Varnish operates outside of your application and caches the entire HTTP response such as the whole HTML document returned by your application.

Varnish is extremely effective because it will cache the final resulting HTML document after all PHP or other server side processing is done. This means that when varnish delivers a page from cache, it avoids running the PHP code at all and consequently any database queries involved in generating the document. Delivering a cached page from Varnish is like delivering a static HTML file.

Varnish is built for dynamic and content heavy sites so it allows you a good deal of flexibility in controlling how pages are cached using the Varnish Configuration Language. It also lets you dynamically expire cache entries from your application.

This flexibility and speed has made it very popular and effective with Drupal, though it can be tricky to configure.

Websites we currently know of using Varnish:

  • BBC
  • Wired
  • Vimeo
  • Zappos
  • MorningStar
  • Business Insider
  • Thinkgeek

Application Cache (eg. Drupal’s caching system)

An in-application cache like Drupal’s built in caching system is used within the application to save calculated values or generated output for later use. Drupal is filled with operations that can be cached. When you put content into an input field, it’s run through various input filters. This output can be cached so the same content doesn’t have to be filtered again. Similarly, when executing a hook, Drupal has to determine all the modules that implement that hook. This is information that it caches after it scans all the modules. It will re-scan when you enable a new module or if you clear the cache. The resulting cache data can be stored in different places but it typically is stored in the database and in the file system. It can also take advantage of APC or Memcached object stores to hold this data. This is better because it will be stored in shared memory or in memory.

Conclusion

These caching systems will cache data at different stages of the application life cycle, so they can certainly be used together but you should be mindful of how they interact, and what each one does. Let’s break it down with a quick re-cap.

  1. APC opcode cache will cache your PHP opcode. There’s really no reason not to use this with PHP. It will simply make your PHP run faster.
  2. APC object cache can be used as a shared memory back-end for your application cache.
  3. Memcached can be used as an in-memory, distributed back-end for your application cache.
  4. Varnish can be used as a reverse proxy to externally cache HTTP requests.

You would choose between APC and Memcached as a back-end for your application cache, but otherwise you could use the APC opcode cache, an object cache back-end, and Varnish all together.

It’s good to use multiple caching strategies and have separated caches because you can cache different aspects of your web application and you can also employ different strategies for clearing each cache. The more pieces of cached data that are valid, the faster your application will load. A good caching structure will mean that on any request to your server, only a small portion of the cached data needs to updated and you can still provide fresh, dynamic content for your users.

 

Comments

  1. KelBraish says

    Cialis Contre Levitra [url=http://curerxshop.com]cialis 5mg best price[/url] Buy Viagra Overnight Buy Clobetasol Medicine With Free Shipping

  2. TubesexWeelo says

    I have recently started a website, the information you offer on this website has helped me greatly [url=https://sexytuber.com]nude free porn[/url]. Thanks for all of your time & work.

  3. Anonymous says

    ϟoϡͥiPhoneXS`|ȥiPhoneXS`|åiPhoneXS `|ͥiPhoneXS`|Phone`֥ɥԩ`˚ … ԩ` ͨ؜_ ͥiphone8 `亮ͥiPhone8`_ե8`֥ɥͥ_ͥiPhone`֥_ … ֥__֥Я` iphone8plusͥ__ۥ8plusЩ`ͥ__ͥ iPhone8plus ֎__iphone8plusͥ-iphone`֥ɥԩ`|֥ɥ`ѩ`ԩ`ͨ؜.
    륤ȥiPhone`

  4. BbokwnkCop says

    They said the formulations treatment was originally more to a vagotonic sichtbar dabant put regularly by Sprout than to free information. order generic viagra Identification of the cytochrome P450 enzymes involved in the N-demethylation of sildenafil.

  5. generic viagra says

    “When I joined Facebook in 2016, my mom was so proud of me, and I could walk around with my Facebook backpack all over the world and people would stop and say, ‘It’s so cool that you worked for Facebook.’ That’s not the case anymore,” a former product manager says. buy viagra Controlled substance, a mask everytime, do get go about using this plaque begins as possible.

  6. buy generic viagra says

    There are significant side-effects, and because I hadn’t needed it in the past, I knew that I shouldn’t need it in the present or future. viagra online At least eight candidates ran for the nomination.

  7. generic viagra says

    Viagra works during 5-6 hours and this time is usually enough in order to relax, switch off from everyday fuss and concentrate on getting the feeling of satisfaction. buy viagra Before the wars in iraq and afghanistan, combat overseas assignments are also at higher risk for preterm and high-risk infants section three: General management of kawasaki disease, of fever: Children with sickle cell disease.

  8. BBWBabesweer says

    I think other web-site proprietors should take this website as an model, very clean and excellent user friendly style and free italiangn, as well as the content [url=https://bbwporn.me]plumper anal porn[/url]. You are an expert in this topic!

  9. order viagra online says

    By the holidays in 2018, Facebook was beginning to seem like Monty Python’s Black Knight: hacked down to a torso hopping on one leg but still filled with confidence. where to buy viagra Since the FDA approved Addyi in August 2015, feminist debate on these questions has raged.

  10. viagra online canadian pharmacy says

    Another said, “My eyes rolled to the back of my head” watching people make specific personnel demands of Zuckerberg, including that Kaplan undergo sensitivity training. buy viagra Orgasm had widely become the presumed measure of womenʼs satisfaction in both feminist writing and sex research by the middle 1970s.

  11. Anonymous says

    Shop our homecoming dresses for this year’s party. With many styles and colors, find the perfect homecoming dress for you,Looking for that perfect homecoming dress?Vdressy’s Bridal offers inexpensive prom dresses in long, short & colorful styles.#homecomingdresses,#homecomingdresses2019,#shorthomecomingdresses,#redhomecomingdresses,#blackhomecomingdresses,#cheaphomecomingdresses,#cheaphomecomingdresses2019,#cheaphomecomingdressesunder100,#cheapplussizehomecomingdresses,#cheapredhomecomingdresses

  12. formal evening gowns cheap says

    Take our What’s Your Bridal Style? #BridesmaidDresses,#CheapBridesmaidDresses,#BridesmaidDresses2019,#lalamiracom.Wedding Dress 2019 & Style | Lalamira’s Bridal -What is your bridal style?#BridesmaidDresses,#CheapBridesmaidDresses,#BridesmaidDresses2019,#lalamiracom.
    formal evening gowns cheap

  13. Anonymous says

    Cheap Bridal Dress, Affordable Wedding Gown | Vdressy,Cheap Wedding Dresses & Gowns Under $100,Find cheap wedding dresses under $100 dollars in beautiful simple designs to glamorous gowns in beautiful designs and high quality.

  14. cheap formal dresses under 30 says

    What is your bridal style? – #BridesmaidDresses,#CheapBridesmaidDresses,#BridesmaidDresses2019,#lalamiracom.With so many wedding dress styles to choose from, it’s nearly impossible to know what style suits you best.#BridesmaidDresses,#CheapBridesmaidDresses,#BridesmaidDresses2019,#lalamiracom.
    cheap formal dresses under 30

  15. Anonymous says

    Cheap Prom Dresses – The Dress Outlet:Cheap Party Dresses, Inexpensive Formal Evening GownsProm dresses for plus size. Beautiful selection of short or long prom dresses under 100 in your favorite colors. Get one at cheap price

  16. Anonymous says

    Looking for Cheap Flower Girl Dresses Online? Search for these Elegant Baby Girls Dresses at vdressy.com.Cheap flower girl dresses of different color and styles for you to choose from. US2-14 Sizes and Custom Sizing available.Looking for colorful unexpensive flower girl dresses? We specialize in flower girl dresses 2019 at cheap price with wide selections of flower girls style.#flowergirldresses,#flowergirldresses2019,#cheapflowergirldresses,#flowergirldresseslace,#flowergirldressesonsale,#flowergirldressessydney,#flowergirldressesforwinterwedding,#flowergirldressesforweddings,#flowergirldressessale,#flowergirldressesuksale,#cheaplaceflowergirldresses,#cheapsilverflowergirldresses,#cheappurpleflowergirldresses

  17. Anonymous says

    Marriage lets you annoy one special person for the rest of your life. While you may share your sorrows and joys, sharing fun and happy_Lalamira!!!www.lalamira.comWedding Dress 2019 & Style Finder|Lalamira’s Bridal #BridesmaidDresses,#CheapBridesmaidDresses,#BridesmaidDresses2019,#lalamiracom.

  18. long evening gowns under 200 says

    Flower Girl Dresses in Various Colors & Styles | Find the perfect flower girl dresses at Lalamira’s Bridal.Our flower girl dresses come in a variety of styles & colors including lace, tulle, purple & gold.Shop flower girl dresses and junior bridesmaid dresses to fit your style.#FlowerGirlDresses,#CheapFlowerGirlDresses,#FlowerGirlDresses2019
    long evening gowns under 200

  19. Anonymous says

    Browse wedding dresses at Vdressy.Shop dresses that match your bridal style,from vintage & boho to classic styles,you’ll find the perfect one for you.#weddingdresses,#cheapweddingdresses,#cheapbridesmaiddresses

  20. Anonymous says

    Cocktail & Party Dresses | Free shipping & returns on cocktail & party dresses-Shop sequin, lace, mesh, beading in a variety of lengths & styles from top brands.Stand out in lace and metallic cocktail dresses and party dresses from all your favorite style!Trendy Cocktail and Party Dresses for Women | Latest Styles.

  21. sexy gala dresses says

    #promdresses,#promdresses2019,#promdresseslong,#promdresseslace,#cheappromdresses,#cheappromdressesunder200,#cheappromdressesukunder200,#cheapplussizepromdressesunder200,#cheapredpromdresses,#cheapmodestpromdresses
    sexy gala dresses

  22. short formal dresses says

    Shop Discount Wedding Dresses: Wedding Dress Sale | Vdressy’s Bridal,Purchase your favorite 2019 style Wedding Dresses right now, you can also get a big discount. #weddingdresses,#cheapweddingdresses,#cheapbridesmaiddresses
    short formal dresses

  23. simple wedding dresses under 100 says

    Cheap Evening Dresses & Formal Gowns Online | Browse fashion styles of evening dresses and gowns,1000s of styles with custom size & 52+ colors, long or short evening dresses now up to 75% off!Shop for cheap Evening Dresses? We have great 2019 Evening Dresses on sale.Buy cheap Evening Dresses online at vdressy.com today!#eveningdressesuk,#eveningdresses2019,#eveningdresseslace,#eveningdressesireland,#cheapeveningdresses,#cheaplongeveningdresses,#cheaplongeveningdressesuk,#cheapplussizeeveningdressesunder200,#cheapplussizeeveningdresses,#cheapwhiteeveningdresses
    simple wedding dresses under 100

  24. Anonymous says

    Looking for the perfect Cocktail Dress for an upcoming event? Browse our selection of trendy Cocktail Dresses. FREE SHIPPING on qualifying purchases!Cocktail Dresses & Party Dresses for Women | Perfect for any holiday party or cocktail hour, in styles like lace, sequin or off the shoulder.Cocktail Dresses For Women!

  25. Anonymous says

    Cheap Wedding Dresses 2019, Bridal Wedding Gowns Online UK- Seek fashion & cheap bridal/wedding gowns from thousands of quality wedding dresses online. Various affordable wedding dresses/gowns with big discount.#weddingdresses,#cheapweddingdresses,#cheapbridesmaiddresses

  26. Anonymous says

    Browse wedding dresses at Vdressy.Shop dresses that match your bridal style,from vintage & boho to classic styles,you’ll find the perfect one for you.#weddingdresses,#cheapweddingdresses,#cheapbridesmaiddresses

  27. wedding ball gowns under 200 says

    Look extra extravagant and turn heads in our range of cocktail dresses, ideal for those up and coming special events that you have jotted in your diary. Choose from a variety of styles & colors.Shop online for Designer Cocktail Dresses: Lace, Bodycon & More.Shop our collection of womens cocktail and party dresses. Browse our luxury designer brands. Free shipping on all orders over $99!
    wedding ball gowns under 200

  28. princess prom dresses says

    Bridesmaid Dresses, Affordable & Wedding Bridesmaid Gowns Online Sale | LaLaMira – lalamira.Browse our collection of Bridesmaid Dresses,all offered at amazingly affordable prices.Plus size bridesmaid dresses also available!Wedding Dress 2019 & Style Finder|Lalamira’s Bridal #BridesmaidDresses,#CheapBridesmaidDresses,#BridesmaidDresses2019,#lalamiracom.
    princess prom dresses

  29. Anonymous says

    ֥ɥԩ` supreme ͨ؜ ,luxurybrandsale2019֥ɥ󥺥`ѩ`ԩ` ,ԩ` T LT ԩ` å¥å ԩ` ,hxqiu.com` жӤ һ ީ` N ީ`˥`. 륤ȥ 磻 ԩ` ֥T 륤ȥ ԩ` ֥T ,ީ` supreme`ѩ`ԩ`֥ɡީ`17ԩ“.
    ץ`ॳԩ`

  30. Anonymous says

    ֥ɥԩ`եָΥ󥯥`륢ȥåȤǤluxurybrandsale2019һȤُƤߤȥȥꥳˤʤ뤫⤷ޤ衫ʤʤ顢pabrand.comΥԩ`֥Ʒ؜Iһǡ ?Ʒ|ǤṩΥ`ѩ`ԩ`ƷϟoΥ֥ɥԩ`T,ӤƤ2019֥ɥԩ`,󥯥` ԩ`˚ݥ󥯥` `ѩ`ԩ` 󥸥㥱å߼ꡣgƷQƷȤͬˡϤʤ˰ĤƤ餤ޤʥ󥯥` 󥸥㥱å.
    쥤Х ֥ޥ` ԩ`

  31. Anonymous says

    å`ѩ`ԩ`Ʒ|^luxurybrandsale2019 2019עĿǥ䶨˚ݥƥå gucci t ԩ`å ǥ` ԩ`åԩ`b롰 åäƤȫLҤΤǤȤ äơΤ褦ɫϤ.åΥ˥ΤयؤäƤ褦Ǥ`ُ뤵줿Ρץ쥼ȤǤäΡ˥ۥΤǤ礦 ؤˤǤ֤䤹åΥǤҊ֤򤴽B餤ޤ
    Щ`Х` ȩ`ȥХå ԩ`

  32. Anonymous says

    `ѩ`ԩ`tĴ,֥ɷԩ`B,luxurybrandsale2019֥ɥԩ`2018`ѩ`ԩ`ͨ؜,ͥ ԩ` ,å ԩ` ,᥹ ԩ` ,ץ ԩ` ,ߥ奦ߥ奦 ԩ`.`ѩ`ԩ`ȫȣ֥ɥԩ`ڥͨ؜꣡2019 ˚ݤΥ󥯥`륹`ѩ`ԩ`,󥯥`륹`ѩ`ԩ`,ץ`ॳԩ`,󥯥`륳ԩ`,륤ȥԩ`,ͥԩ`,åԩ`.
    fendi ԩ`

  33. Anonymous says

    ϥ른ީ`˥`󥺼Ʒؤ˴˚luxurybrandsale2019른ީ` `󥺂ҎƷηNN ȡBޤSuperem`󥺥ԩ`른 ީ`˥`󥺼른ީ`˥`󥺂һThxqiu.com,ީ` ` ԩ` _ީ`˥`󥺥ԩ`2019.
    ͥ ԩ`

  34. Anonymous says

    `ѩ`ԩ`tĴ,֥ɷԩ`B,luxurybrandsale2019֥ɥԩ`2018`ѩ`ԩ`ͨ؜,ͥ ԩ` ,å ԩ` ,᥹ ԩ` ,ץ ԩ` ,ߥ奦ߥ奦 ԩ`.`ѩ`ԩ`ȫȣ֥ɥԩ`ڥͨ؜꣡2019 ˚ݤΥ󥯥`륹`ѩ`ԩ`,󥯥`륹`ѩ`ԩ`,ץ`ॳԩ`,󥯥`륳ԩ`,륤ȥԩ`,ͥԩ`,åԩ`.
    󥯥` ԩ` ͨ؜

  35. Anonymous says

    2019supreme `ѩ`ԩ`ͨ؜luxurybrandsale2019,2019ץ`ॳ,֥ ԩ` , LOUIS VUITTON ԩ`, supreme ԩ`, GUCCI ԩ` , HERMES ԩ` , PRADA ԩ`,YSL ԩ` ֥ ԩ` ީ` ԩ` D&G ԩ` Щ`Х` ԩ` ץ ԩ` å T ԩ` ȥ ԩ` I.
    եǥ Хå ԩ`

  36. Anonymous says

    󥺥եå󡢥ץ` T ԩ` SUPREME `ѩ` ԩ` 㥱å.Ȥϥ֥ɥԩ`Ʒͨ؜Gucciѥԩ`å󥺷ԩ`ʼᡢå󥺥륳ԩ`åѥԩ`å󥺣ԥĥԩ` å󥺥ݥĥԩ`å󥺥ĥԩ`åLԥĥԩ`.
    եǥ `ѩ`ԩ`

  37. Son Guadeloupe says

    My friends have never had any complications with Bitcoin Miners UK in well over five years, I began using https://bitcoinminersuk.com/ a good while ago. I found them to be superior service and better priced. I lease various cloud-mining contracts from them and have found them perfect. Their site hasn’t been updated in ages, I enquiered about this and the guy I spoke to said all the customers are established and they don’t need more business, although I received an email the other month saying their site is due to be updated as they have aquired more people to host their hardware in Iceland. So I would definately check them out.

  38. eebest8 smm says

    Hmm is anyone else experiencing problems with the pictures on this blog loading? I’m trying to figure out if its a problem on my end or if it’s the blog. Any feed-back would be greatly appreciated.
    eebest8 seo

  39. Like says

    Status Auto Liker, Increase Likes, Autoliker, Autolike, Photo Liker, autolike, Autoliker, auto like, Auto Liker, Auto Like, Autolike International, Status Liker, auto liker, ZFN Liker, Working Auto Liker, Photo Auto Liker, autoliker

Leave a Reply

Your email address will not be published.