Cache
A cache is a temporary storage file intended to speed up an application or service.
Contents
Specifications
- JCACHE - Java Temporary Caching API (JSR-107): https://jcp.org/en/jsr/detail?id=107
Cache Architectures
Network-side
DNS cache
DNS Caching occurs when top-level DNS servers hold on to a mapping of popular (commonly visited) and/or recently visited domain names and their corersponding IPv4/IPv6 address ranges.
Load Balancer
Reverse Proxy
Caching at the Load Balancer level.
Cloud
CDN cache
On top of just loading content quickly, there are regional differences in content connection speeds (ISP quality), network routes (for legal/political reasons, etc), blocking/monitoring (i.e. political reasons). For that reason, in serving traffic globally it is often most performant and sometimes legally optimal to use a CDN with data centers within the countries/sub-regions you officially do business.
Cloud-based App cache
Short of or in collaboration with a full file-level CDN, a Cloud-based Caching platform such as Hazelcast Cloud or any of the equivalent Cloud platforms’ caching mechanisms (AWS, Azure, GCP, etc) may be leveraged by an application, rather than relying solely on its own self-hosted or internal caching mechanism(s) to improve performance of its data retrieval.
Server-side
Web Service cache
As in a common web server layer deployed on top of a slower application stack that can render pages dynamically but may not be as efficient for serving content quickly (aka. a Dispatcher, or "web optimization" server).
Sidecar
Microservice-level cache.
Application cache
Application Cache is held in-memory for the lifetime of an application (until the next restart, or based on some internal expiry policy or caching mechanism).
Client-side
Browser Cache
Client-side caching happens in the user's browser.
<meta http-equiv="cache-control" content="max-age=0" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="pragma" content="no-cache" />
Expires
Example "expires" headers used to set refresh intervals for specific pages, content or entire web applications:
<http-equiv="expires" content="0" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
- Page Expire For Html, Asp, Php, Java: http://www.blect.net/blog/?p=208
- Cache it! Solve PHP Performance Problem: http://www.sitepoint.com/article/caching-php-performance/
BlurHash
A lazy loading image caching companion technique to show a gradient color that matches/approximates the image in place of an actual image until It has loaded. This is particularly useful in Mobile Applications or any applications that need to load large image assets remotely/externally through a network connection.
- BlurHash: https://blurha.sh/ | SRC
- BlurHash Java SDK: https://github.com/hsch/blurhash-java
Resources
- Refresh Your Cache: https://www.refreshyourcache.com/ (instructions for how to refresh your browser cache in the prmiary modern Device/OS/Browser combinations)
- dzone -- Memcached (REFCARDZ): https://dzone.com/refcardz/getting-started-with-memcached | DOWNLOAD
- dzone -- Java Caching (REFCARDZ): https://dzone.com/refcardz/java-caching | DOWNLOAD
- Caching best practices & max-age gotchas: https://jakearchibald.com/2016/caching-best-practices/
- JSR107 (JCache): https://github.com/jsr107/jsr107spec
- Choosing a cache: https://blog.frankel.ch/choose-cache/1/ (includes VIDEO... "Guided tour of Caching patterns")
Tutorials
- Caching Tutorial: http://www.mnot.net/cache_docs/
- Cache-Control for Civilians: https://csswizardry.com/2019/03/cache-control-for-civilians/
- Speed Up Your Website - By Example (html/css/js cache control): http://www.codeproject.com/KB/HTML/SpeedUpWebsite.aspx
- Yahoo! Developer network - Best Practices for Speeding Up Your Web Site (caching, minimizing requests, etc...): http://developer.yahoo.com/performance/rules.html
- PHP (file) Caching: http://www.developertutorials.com/tutorials/php/php-caching/
- How to output PHP to Text (.txt cache output file): http://www.joe2torials.com/view_tutorial.php?view=61
- Java - HttpUrlConnection returns cached response every time: https://stackoverflow.com/questions/34534945/java-httpurlconnection-returns-cached-response-every-time[7][8][9]
- HTTP cache with Spring examples: http://dolszewski.com/spring/http-cache-with-spring-examples/
- EXPIRES HEADER -- How can I avoid making multiple HTTP calls for content that hasn't changed? Is it possible to cache it? Is there a way to set this in the header?: http://www.jguru.com/faq/view.jsp?EID=1311010
- Using "ETAG"s and "Last-Modified" headers to improve performance with HTTP conditional requests: https://www.bizcoder.com/using-etags-and-last-modified-headers-to-improve-performance-with-http-conditional-requests
- Introduction To Ehcache: https://www.baeldung.com/ehcache | SRC
- Ehcache docs -- Hello, Ehcache: http://www.ehcache.org/documentation/2.7/get-started/introduction.html[10][11][12]
- Cache Scope with EhCache: https://dzone.com/articles/cache-scope-ehcache
- Introduction To Ehcache: http://www.baeldung.com/ehcache[13]
- Using SelfPopulatingCache in Ehcache: https://dzone.com/articles/using-selfpopulatingcache
- Configure a Nonstop Cache Programmatically in Ehcache: https://dzone.com/articles/configure-nonstop-cache
- Shutting Down Ehcache Properly: https://dzone.com/articles/shutting-down-ehcache-properly
- Spring and ehCache: https://dzone.com/articles/spring-and-ehcache
- Implementing Ehcache using Spring context and Annotations: https://dzone.com/articles/implementing-ehcache-using
- What's the difference between Cache-Control: max-age=0 and no-cache?: https://stackoverflow.com/questions/1046966/whats-the-difference-between-cache-control-max-age-0-and-no-cache
- Using Cache-Control Headers: https://www.maxcdn.com/one/tutorial/uing-cache-control-headers/ (86400s=24h=1d)
- Introduction to JCache: https://www.baeldung.com/jcache
[14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24]
- The JPA and Hibernate second-level cache: https://vladmihalcea.com/jpa-hibernate-second-level-cache/ (Database caching)
External Links
- wikipedia: Web cache
- wikipedia: DNS cache
- wikipedia: P2P caching
- wikipedia: Database caching
- wikipedia: Cache-Control
- wikipedia: Memcached
- wikipedia: Ehcache
- wikipedia: Time to live
- An Introduction to Caching - How and Why We Do It: https://dzone.com/articles/introducing-amp-assimilating-caching-quick-read-fo
- To Cache or Not to Cache?: https://dzone.com/articles/cache-or-not-to-cache
- What is the difference between no-cache and no-store in Cache-control?: https://stackoverflow.com/questions/7573354/what-is-the-difference-between-no-cache-and-no-store-in-cache-control
- How to differentiate between Time To Live (TTL) and Time To Idle (TTI) in ehcache: https://stackoverflow.com/questions/2583429/how-to-differentiate-between-time-to-live-and-time-to-idle-in-ehcache (TTL is time until expiry or total time from now until flush, TTI is max time to allow it to go until considering stale and clearing)
- EhCache's Pinning, Expiration, and Eviction: http://www.ehcache.org/documentation/2.7/configuration/data-life.html
- Yahoo -- Performance Research, Part 2 - Browser Cache Usage - Exposed!: https://yuiblog.com/blog/2007/01/04/performance-research-part-2/
References
- ↑ Where Is My Cache? Architectural Patterns for Caching Microservices: https://dzone.com/articles/where-is-my-cache-architectural-patterns-for-cachi
- ↑ Using <meta> tags to turn off caching in all browsers?: https://stackoverflow.com/questions/1341089/using-meta-tags-to-turn-off-caching-in-all-browsers
- ↑ Useful HTML Meta Tags: www.i18nguy.com/markup/metatags.html
- ↑ What is the meaning of the html tag HTTP-EQUIV "CACHE-CONTROL": https://www.metatags.org/meta_http_equiv_cache_control
- ↑ Different kinds of caches: https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching
- ↑ Java - Generate BlurHash Examples: https://www.woolha.com/tutorials/java-generate-blurhash-examples
- ↑ setDoInput and setDoOutput in Java HttpURLConnection: https://stackoverflow.com/questions/5583064/setdoinput-and-setdooutput-in-java-httpurlconnection
- ↑ Adding header for HttpURLConnection: https://stackoverflow.com/questions/12732422/adding-header-for-httpurlconnection
- ↑ How to modify the header of a HttpUrlConnection: https://stackoverflow.com/questions/480153/how-to-modify-the-header-of-a-httpurlconnection
- ↑ How does EhCache work in a clustered environment: https://www-01.ibm.com/support/docview.wss?uid=swg21519527
- ↑ Using ehcache and verifying that it works with JPA and springframework: https://www.gridshore.nl/2008/04/29/using-ehcache-and-verifying-that-it-works-with-jpa-and-springframework/
- ↑ Ehcache - A Java Distributed Cache: http://highscalability.com/ehcache-java-distributed-cache
- ↑ What is Ehcache in Java?: https://www.quora.com/What-is-Ehcache-in-Java?share=1
- ↑ What is JCache?: https://redisson.org/glossary/jcache.html
- ↑ JCache RI - note that the reference implementation should not be used in PROD: https://github.com/jsr107/RI (missing tiered storage & distributed caching)
- ↑ Introduction to JCache (JSR 107): https://dzone.com/articles/introduction-jcache-jsr-107
- ↑ Apache Ignite (data grid) - OSS JCache provider: t
- ↑ Apache Ignite - JCache and Beyond: https://apacheignite.readme.io/docs/jcache
- ↑ Apache Camel - JCache component: https://camel.apache.org/components/latest/jcache-component.html
- ↑ Oracle Coherence - JCache: https://www.oracle.com/middleware/technologies/coherence.html
- ↑ Oracle Coherence - Working with JCache: https://docs.oracle.com/middleware/1213/coherence/tutorial/jcache.htm
- ↑ Hazelcast - Java Cache implementation: https://hazelcast.com/glossary/jcache-java-cache/
- ↑ Terracotta - EH Cache: http://www.terracotta.org/terracotta-ehcache/
- ↑ Infinispan - JCache: https://infinispan.org/
See Also
PHP | Java | AJAX | JavaScript | CSS | Image | Optimization | CDN