Caching: Storing the result of an operation so that future calls can be fasten

cache hit: if value found in cache
cache miss: if not found in cache
When to cache:
  - when computaion is slow
  - when the output is same for a particuler input
  - when computaions run multiple times
  - When reads are fixed based on cost
  
Use of caching:
  - To improve performance
  - Reduce the server load
  - Fault tolaerance
  

Type of caching:
  - client side or Local cache: caching by browser, server responses stores at client side(eg. http caching)
  - server side/application cache: server stores the heavy DB calls, func with heavy computaions (memcached, redis)
  - proxy cache: an intermediate server uses for caching
  - Gateway cache
  

Use of e-tag:
HTTP ETag caching is a mechanism to validate http web cache, when server detects the tag it responds 
with a tiny 304 Not Modified response instead of the regular 200
- e-tags are generated by the server and manage by the browser
 client ->sends request for a resource/image , server response resource/image with a uniqe e-tag 
 Next time when client send a request for the same resource with e-tag in property if-none-match->server just match the e-tag,
 if no change in image, server indicate the client no change(http status 304 Not modified) in image and does not send image back
 in the response(which improve performance and optimize n/w bandwidth, server does not have to consume the CPU/memory to buld the resource)
 
Cons of e-tag:
  - when they behind the load balancer, where diff server generate the diff-2 e-tag fo the same resource, this problem can be solved by 
    configuring the web servers correctly
  - hard to manage, if you write your own client	
  

memcache: 
 - Memcached is a simple volatile cache server. It allows you to store key/value pairs where the value is limited to being a string up to 1MB.
 - Memcached is an open source, high-performance, distributed memory caching system intended to speed up
   dynamic web applications by reducing the database load.
 - It is a key-value dictionary of strings, objects, etc., stored in the memory, resulting from database calls, API calls, or page rendering  

 - The key features of Memcached are as follows −

	It is open source.

	Memcached server is a big hash table.

	It significantly reduces the database load

	It is perfectly efficient for websites with high database load.

	It is distributed under Berkeley Software Distribution (BSD) license.

	It is a client-server application over TCP or UDP.
	
Memcached is not −
a persistent data store
a database
application-specific
a large object cache
fault-tolerant or highly available	

$sudo apt-get update
$sudo apt-get install memcached
Memcached is running on the default port 11211.

Redis:
 - Redis can do the same jobs as memcached can, and can do them better.
 - It can store key/value pairs too. In redis they can even be up to 512MB.
 - It is persistent by default
 - Unlike memcached which is limited to strings, it support diff data types to be cached
    list, set, geo, hashes, sorted sets, bitmap
 - Support clustering: 
   If one instance of redis/memcached isn't enough performance for your workload, redis is the clear choice.
   Redis includes cluster support and comes with high availability tools (redis-sentinel) right "in the box 
 - pub/sub machanism
 - Since redis is an nosql database, it allocates memory as it needs it — the more objects you put in it,
   the more memory it uses. The maxmemory option does not strictly enforces upper memory limit usage.
  
	
