What are the goals of client and server-side caching?
To temporarily store data locally to improve performance and efficiency during the data retrieval process.
How does server-side caching work?
When a client issues a request from the server, the server will:
- Check the cache
- If present (cache hit), it will serve it from the cache.
- Otherwise (cache miss), it will request the data from its primary store and persist in cache.
What are some characteristics of server-side caching? (Location, Control, Type of Data)
LOCATION
The cache is maintained on the server.
CONTROL
Cache is controlled fully by the server.
TYPE OF DATA
Things like database query responses, page responses, and objects.
What are two pros of server-side caching? What about two drawbacks?
PROS
Reduced load times and reduced overhead on server/backend (databases, etc.)
CONS
Additional resources to facilitate the cache and implementation of cache invalidation strategies to avoid overly stale data/inconsistency
How does client-side caching work?
Data is stored on the client device itself to prevent issuing requests to the server for it.
What are some characteristics of client-side caching? (Location, Control, Type of Data)
LOCATION
The cache is maintained on the client.
CONTROL
Cache is controlled by the client however it can be influenced by the server (e.g. server may say how long to cache things for, etc.)
TYPE OF DATA
Typically asset-based items like images, style sheets, scripts, some application specific data.
What are two pros of client-side caching? What about two drawbacks?
PROS
Reduced network traffic and support for local/offline use cases.
CONS
Storage limitations on the client and stale data if not regularly synchronized with server.
What are the key differences between server-side and client-side caching? (Location, Freshness, Resources)
LOCATION
Server-side caching is obviously at the server (which benefits all users) while client-side is on a single client (benefiting that one)
FRESHNESS
Server-side can better maintain fresh data as it’s in full control of the cache while client-side must rely on synchronizing with the server.
RESOURCES
Server-side obviously uses server resources (typically much larger than client) which is perfect as it affects multiple users while client-side uses more limited client resources.