Not a member? Why not join us or log in? (Free to Post your Articles and Blogs on Technology.)

How to Configure squid for Youtube caching

Home > Linux>
Dated : October 7, 2008
Follow us on Twitter
Connect with us on Facebook
Subscribe via RSS Feed
Add Techgurulive to Google

To cache Youtube videos using Squid proxy server so that subsequent requests for the same video can be served from the cache saving the loading time and some bandwidth.

Use Cases

To reduce the loading time for the subsequent requests on a shared network.
To save some bandwidth which is wasted in serving the same video again and again.
When the clients on your proxy are in thousands and they love browsing youtube all the time (universities are typical examples ), the 2nd factor becomes an issue.
When you don’t want to hack the refresh_pattern in squid and don’t want to disturb the dynamic content.

How to proceed

I tried a lot of squid hacks listed all around the web. But none of them seems to work for me. And even if they work, the weird load balancing system of youtube servers result in weird behaviors. I was working on my GSOC project which is also related to caching but of RPMs, when I got this idea of caching youtube videos using custom squid redirectors. Sometime back, I posted a tutorial on how to write custom squid redirectors in Python. I extended that to write a squid plugin to cache youtube videos which I call youtube_cache.

Method of operation for caching

Squid gets a request for a url from the client.
youtube_cache taps the url
CHECK: if url is .youtube.com and has a get_video request
Extract the 11 character long unique video id ( this is different for all the videos on youtube)
CHECK: if video is already in cache
CHECK: if cached video is newer or same as remote video (last-modified timestamp)
Serve from cache and exit
ELSE: Download and cache the new video in background ( using daemon forking )
ELSE: Download and cache the new video in background ( using daemon forking )
ELSE: url is not from any of the youtube servers. Let squid handle it


Tags:, , , , ,

Written by Editor


Not Getting : Search to find what you are looking for


Liked this article? To continue getting our latest free Howtos and Tutorials,
you can also grab the RSS feed or Subscribe to Techgurulive by Email

5 Responses to “How to Configure squid for Youtube caching”

  1. Kulbir Saini Says:

    I have written a squid url rewriter plugin in python to handle caching from 10 websites. Please check http://cachevideos.com/.

  2. Manoj Says:

    How to auto clear cache on Squid

  3. Matheus Says:

    Did you talk about how to configure it. But you don’t show your youtube_cache. Can you send it to me?

    Or explain better how to do a plugin to Squid? I’m searching but I didn’t found anything about cache plugin to it.

  4. Enhance your ISP offering with YouTube Caching « NetEqualizer News Blog Says:

    [...] Note with Squid Proxy you’ll need a third party module to cache YouTube [...]

  5. moon Says:

    best result of video cache in production level is thundercache 3.0 witch is very simple and use full. wit squid u can use it as put some lines to just filter and redirect the youtube requestes to an other service as thundercache to handle not by squid.

Leave a Reply



This Howtos posted under : Home > Linux->

How to Configure squid for Youtube caching