By offloading work to a CDN, caching can reduce network traffic and the load on the origin server. Doing so reduces cost and resource requirements for the application, even when there are large numbers of users.
Similar to how caching is implemented in a web browser, you can control how caching is performed in a CDN by sending cache-directive headers. Cache-directive headers are HTTP headers, which are typically added by the origin server. Although most of these headers were originally designed to address caching in client browsers, they are now also used by all intermediate caches, such as CDNs. Two headers can be used to define cache freshness: Cache-Control and Expires.
Cache-Control is more current and takes precedence over Expires , if both exist. There are also two types of headers used for validation called validators : ETag and Last-Modified. ETag is more current and takes precedence over Last-Modified , if both are defined. When the cache is stale, HTTP cache validators are used to compare the cached version of a file with the version on the origin server.
Not all resources can be cached. The following table shows what resources can be cached, based on the type of HTTP response. Resources delivered with HTTP responses that don't meet all of these conditions cannot be cached. The following table describes the default caching behavior for the Azure CDN products and their optimizations.
Honor origin : Specifies whether to honor the supported cache-directive headers if they exist in the HTTP response from the origin server. Azure CDN makes no guarantees about minimum amount of time that the object will be stored in the cache.
Cached contents may be evicted from the CDN cache before they are expired if the contents are not requested as frequently to make room for more frequently requested contents. A website has only a limited way of administering client-side caching. It can tell a cache how long to store saved data. But, a page with images that are changed often, for example, can be requested to expire much sooner, or when the page is updated.
This ensures the end user can regularly see fresh content. Files and content that are saved are stored on your computer and are grouped with other files associated with the browser you use. According to Google , every browser has some form of browser cache. Although, some have a more comprehensive system such as those found in major options such as Chrome, Safari, Firefox, and other similar browsers.
So, when a page is updated and the content stored in the cache is obsolete, the browser knows it should flush out the old content and save the updates in its place. Server caching is also fully handled and amistered on the server without any involvement of the end user, or a browser.
Now that website, browser, and server caching have been defined, you may be able to detect the differences. But, laying them all out can be helpful to better understand them. WP Rocket is a powerhouse WordPress caching plugin that specializes in page caching. W Rocket also installs like most other plugins. You can enable caching for desktop and mobile devices as well as toggle caching for logged-in users, and you can set the expiry time for the cache.
There are also advanced file optimization options that can significantly improve site performance including:. You can also integrate the CDN of your choice for even more caching superpowers. With so many different types of caching options to speed up your WordPress site, it can be difficult to wrap your head around all of them. That includes what a site, browser, and server cache all happen to be.
The following code calls Get to fetch the cached time:. A cached item set with a sliding expiration only is at risk of becoming stale. If it's accessed more frequently than the sliding expiration interval, the item will never expire. Combine a sliding expiration with an absolute expiration to guarantee that the item expires once its absolute expiration time passes. The absolute expiration sets an upper bound to how long the item can be cached while still allowing the item to expire earlier if it isn't requested within the sliding expiration interval.
When both absolute and sliding expiration are specified, the expirations are logically ORed. If either the sliding expiration interval or the absolute expiration time pass, the item is evicted from the cache.
The following code gets or creates a cached item with both sliding and absolute expiration:. These methods extend the capability of IMemoryCache.
A MemoryCache instance may optionally specify and enforce a size limit. The cache size limit does not have a defined unit of measure because the cache has no mechanism to measure the size of entries.
If the cache size limit is set, all entries must specify size. The ASP. NET Core runtime does not limit cache size based on memory pressure. It's up to the developer to limit cache size. The size specified is in units the developer chooses. If SizeLimit isn't set, the cache grows without bound. NET Core runtime doesn't trim the cache when system memory is low. Apps must be architected to:. The following code creates a unitless fixed size MemoryCache accessible by dependency injection :.
SizeLimit does not have units. Cached entries must specify size in whatever units they deem most appropriate if the cache size limit has been set. All users of a cache instance should use the same unit system.
An entry will not be cached if the sum of the cached entry sizes exceeds the value specified by SizeLimit. If no cache size limit is set, the cache size set on the entry will be ignored.
The following code registers MyMemoryCache with the dependency injection container. MyMemoryCache is created as an independent memory cache for components that are aware of this size limited cache and know how to set cache entry size appropriately.
The size of the cache entry can be set by Size or the SetSize extension methods:. Compact attempts to remove the specified percentage of the cache in the following order:.
0コメント