Understanding Web Cache

15
Web Cache

description

Overview of using cache on websites and some of the implementations of improving your sites performance through cache.

Transcript of Understanding Web Cache

Page 1: Understanding Web Cache

Web Cache

Page 2: Understanding Web Cache

What is Cache?Cache is the storing of data temporarily to improve performance. Cache exist in a variety of areas such as your CPU, Hard Disk and DNS.

CPU Cache Hard Disk Cache DNS Cache

www.prodigyview.com

Page 3: Understanding Web Cache

Our FocusOur focus on this tutorial will be web cache. Web cache is temporary storing of data that is used with delivering a webpage (html, php, javascript, etc).

Page 4: Understanding Web Cache

Why and HowMany sites today are dynamic websites that

1. Use a database connection

2. Written with a scripting language

3. Have changing content

With the amount of technology behind making these sites work combined with larges volumes of traffic going to these sites, cache is very important to improve the user experience and lowering cost of your hardware.

www.prodigyview.com

Page 5: Understanding Web Cache

Basic Flow Without Cache

User

Server

Database

1. U

ser r

eque

st g

oes t

o se

rver

2. Server request content from database

3. Database returns data

4. Ser

ver r

eturn

s con

tent

Page 6: Understanding Web Cache

This Is Ok If…..

1.Not a lot of content

2.Small amount of users/pageviews

This Is Bad If…..

1.Lots of contents

2.Lots of users/pageviews

www.prodigyview.com

Page 7: Understanding Web Cache

Flow With Cache

User

Server

Database

1. U

ser r

eque

st g

oes t

o se

rver

2. Server gets content that is cached

Database only needed to be called for new content

3. Ser

ver r

eturn

s dat

a

Page 8: Understanding Web Cache

Cache Benefits

CPU Cycle Billing: If you are billed by the CPU Cycle, cache can save you money because less of the cpu is used when reading a file rather than a complex database query.

Bottleneck: If there is a bottleneck on your web service such as with your database, not calling the database as often and using cached database queries could help with that bottleneck

Faster UI: Storing cached files, whether in a file in the browser or a location on the server, can lower the amount of time need to load a page. This can make a faster user experience.

www.prodigyview.com

Page 9: Understanding Web Cache

Basic Caching MethodsHeaders: PHP has a cache option set in the headers.

This can be useful for caching external files such as JavaScript and CSS files.

Basic File Cache: Basic file cache is an easy to implement solution for writing and reading cache on a server.

Memcache: A PHP extension for caching files on multiple servers.

Cache Lite: A PHP extension installed through PEAR that caches whole pages or sections of pages.

APC : APC, short for Alternative PHP Cache, is another php extension that cache’s PHP code. It is installed through PECL.

www.prodigyview.com

Page 10: Understanding Web Cache

Higher Level Caching

Varnish: A HTTP accelerator(reverse proxy) that caches data in virtual memory.

Squid: A caching server that can cache DNS, FTP, HTTPS, HTTP, TSL, and SSL protocols.

Apache Traffic Server: A reverse proxy and forward proxy caching server that despite its name, works with Nginx.

XtraDB: If you are using a Mysql database, this caching solution can help optimize performance of your database better than the standard InnoDB.

www.prodigyview.com

Page 11: Understanding Web Cache

Server Cache(Squid or Varnish)

User

Server

Database

1. User request goes to server

2. Cache servers returns cached data

The actual server and the database server are not called unless new content is needed

Cache Server

Page 12: Understanding Web Cache

Database Cache

User

Server

Database

1. U

ser r

eque

st g

oes t

o se

rver

2. Server request content from database

4. Database returns data

5. Ser

ver r

eturn

s con

tent

3. Use cached query

Page 13: Understanding Web Cache

ReviewAs you can see, caching can occur at many levels.

Database (ex: XtraDB)

Server ( ex: Memcache)

DNS/Networks ( ex: Squid)

Client’s Browser (ex: Headers)

Take the time to research these solutions further to see how can they improve your site’s performance.

www.prodigyview.com

Page 14: Understanding Web Cache

ProdigyView and CachingNatively, ProdigyView offers two type of caching:

file cache and memcache. Bot are easy to setup and use.

Caching solutions can be extended by using a third party caching solution or writing an adapter that will change how the cache works.

www.prodigyview.com

Page 15: Understanding Web Cache

API ReferenceFor a better understanding of cache in ProdigyView, visit the api by clicking on the link below.

PVCache

www.prodigyview.com

More Tutorials

For more tutorials, please visit:

http://www.prodigyview.com/tutorials