background preloader

Caching Tutorial for Web Authors and Webmasters

Caching Tutorial for Web Authors and Webmasters
for Web Authors and Webmasters This is an informational document. Although technical in nature, it attempts to make the concepts involved understandable and applicable in real-world situations. Because of this, some aspects of the material are simplified or omitted, for the sake of clarity. If you are interested in the minutia of the subject, please explore the References and Further Information at the end. What’s a Web Cache? A Web cache sits between one or more Web servers (also known as origin servers) and a client or many clients, and watches requests come by, saving copies of the responses — like HTML pages, images and files (collectively known as representations) — for itself. There are two main reasons that Web caches are used: To reduce latency — Because the request is satisfied from the cache (which is closer to the client) instead of the origin server, it takes less time for it to get the representation and display it. Kinds of Web Caches Browser Caches Proxy Caches Gateway Caches Related:  Computing

An Introduction to Graphviz via R. Kelly’s “Trapped in the Closet” Hip Hopera : Rob's Blog As our world becomes more connected it has become of the utmost importance to clearly and easily visualize the structures that represent the modern digital age: the graph. Anyone involved in object oriented programming, artificial intelligence, networks, social media, or of course the fascinating field of graph theory makes heavy use of these structures. Graphs are a fertile topic that I plan to write more about, but for now we will focus on the immediately practical: the fantastic open source graph visualization toolkit Graphviz. Let us explore some of the useful features of Graphviz and its associated description language “dot” by tracing the convoluted relationships of the characters in R. Like every other web tutorial I will solipsistically assume you are using the same OS I am, Ubuntu. At this point our hero, “Sylvester”, played by R. Now compile: Note this will output a .jpg image but many other output formats are possible. As R. Note red edges signify infidelity.

Performance is a Feature We've always put a heavy emphasis on performance at Stack Overflow and Stack Exchange. Not just because we're performance wonks (guilty!), but because we think speed is a competitive advantage. There's plenty of experimental data proving that the slower your website loads and displays, the less people will use it. [Google found that] the page with 10 results took 0.4 seconds to generate. The page with 30 results took 0.9 seconds. I believe the converse of this is also true. Do you, too, feel the need – the need for speed? 1. The golden reference standard for building a fast website remains Yahoo's 13 Simple Rules for Speeding Up Your Web Site from 2007. There's some good advice here, but there's also a lot of advice that only makes sense if you run a website that gets millions of unique users per day. So … a funny thing happened to me since I wrote that four years ago. We've long since implemented most of the 13 items on Yahoo's list, except for one. 2. 3. Did it work?

Rack::Cache Rack::Cache is suitable as a quick drop-in component to enable HTTP caching for Rack-based applications that produce freshness (Expires, Cache-Control) and/or validation (Last-Modified, ETag) information. Standards-based (see RFC 2616 / Section 13).Freshness/expiration based cachingValidationVary supportPortable: 100% Ruby / works with any Rack-enabled framework.Disk, memcached, and heap memory storage backends. News Rack::Cache 1.0 was released on December 24, 2010. Installation $ sudo gem install rack-cache Or, from a local working copy: $ git clone $ rake package && sudo rake install Basic Usage Rack::Cache is implemented as a piece of Rack middleware and can be used with any Rack-based application. require 'rack/cache' use Rack::Cache, :verbose => true, :metastore => 'file:/var/cache/rack/meta', :entitystore => 'file:/var/cache/rack/body' run app More See Also Rack::Cache takes (liberally) various concepts from Varnish and Django’s cache framework.

AlternativeTo - Social Software Recommendations Caching with Rails: An overview 1 Basic Caching This is an introduction to three types of caching techniques: page, action and fragment caching. Rails provides by default fragment caching. To start playing with caching you'll want to ensure that config.action_controller.perform_caching is set to true, if you're running in development mode. 1.1 Page Caching Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. 1.2 Action Caching Page Caching cannot be used for actions that have before filters - for example, pages that require authentication. 1.3 Fragment Caching Life would be perfect if we could get away with caching the entire contents of a page or action and serving it out to the world. Fragment Caching allows a fragment of view logic to be wrapped in a cache block and served out of the cache store when the next request comes in. and you can expire it using the expire_fragment method, like so: You can also use an Active Record model as the cache key: Feedback

Bluetooth-Enabling a Panasonic SA-AK33 Logitech’s bluetooth audio receiver is a great device. It has good range, sound, and build quality. The original plan was to put it into my car to add bluetooth reception, but that plan disappeared when it turned into a install-a-new-stereo project. I’ll just assume you’re as impatient as me, so here’s a video of the end result! Wires Are For Wimps When I approached my roommate about taking apart his stereo and drilling holes into it, he understandably said “no.” Infrared, that’s what. Blind Reverse Engineering I was lost without a known-good source of infrared commands. I found gold after some extended searching; someone had captured the N2QAGB000002 and submitted timing information to LIRC. I first found the capture with a comment describing the protocol as REC 80 encoded. There is a start pulse.Bytes follow in MSB-first bit order.A short trailing pulse to mark the end of a command (sets the previous bit’s space length). The N2QAGB000002’s format differs from pure NEC in a few ways: Code

Seven Advanced Rails Fragment Cache Techniques | CRAZ8 Blog The Rails Fragment Cache is the easiest way of making your view template code run fast. A fragment is a piece of generated output, usually HTML, that is a part of the total output, usually the HTML page, that is returned to a user. The documentation on caching with Rails explains the basics, but doesn’t go into any depth, especially for new use cases and techniques that have been developed and expanded over the last year or so. Here are six techniques and tools that can make your fragment caching easy to manage yet provide the benefits of turbo-charging your view rendering. Don’t Expire Fragments using expire_fragment Frankly, don’t use this. Expire by time If you are using a memcache store for your Rails cache store - and your really should be - then you have the option of expiring fragments by time. <% cache @post, :expire_in => 2.hours %><%= render @post %><% end %> For some use cases, this technique is very useful. Generational (or Key) Expiry Advanced Generational Expiry Summary

Basics of Memory Addresses in C Memory Addresses It is helpful to think of everything in C in terms of computer memory. Let’s think of computer memory as an array of bytes where each address in memory holds 1 byte. If our computer has 4K of memory for example, it would have 4096 elements in the memory array. Confused about pointers, addresses and dereferencing? Say our computer has 4K of memory and the next open address is index 2048. // intialize a char variable, print its address and the next address char charvar = '\0'; printf("address of charvar = %p\n", (void *)(&charvar)); printf("address of charvar - 1 = %p\n", (void *)(&charvar - 1)); printf("address of charvar + 1 = %p\n", (void *)(&charvar + 1)); // intialize an int variable, print its address and the next address int intvar = 1; printf("address of intvar = %p\n", (void *)(&intvar)); printf("address of intvar - 1 = %p\n", (void *)(&intvar - 1)); printf("address of intvar + 1 = %p\n", (void *)(&intvar + 1)); In the output we see the addresses in hexadecimal.

How key-based cache expiration works by David of 37signals There are only two hard things in Computer Science: cache invalidation and naming things — Phil Karlton Doing cache invalidation by hand is an incredibly frustrating and error-prone process. You’re very likely to forget a spot and let stale data get served. That’s enough to turn most people off russian-doll caching structures, like the one we’re using for Basecamp Next. Thankfully there’s a better way. A much better way. The cache key is the fluid part and the cache content is the fixed part. The caching itself then happens in the views based on partials rendering the objects in question. This process makes it trivial to implement caching schemes and trust that you’re never going to serve stale data.

Related: