{"id":14983145,"url":"https://github.com/galaxy-sea/libby-http-cache-control","last_synced_at":"2026-03-12T14:42:19.336Z","repository":{"id":57742552,"uuid":"494717790","full_name":"galaxy-sea/libby-http-cache-control","owner":"galaxy-sea","description":"By reusing previously acquired resources, you can significantly improve the performance of websites and applications. Web caching reduces latency and network traffic, thereby reducing the time required to display resource representations. Become more responsive by using HTTP caching","archived":false,"fork":false,"pushed_at":"2022-06-15T03:30:45.000Z","size":75,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-02T09:27:52.375Z","etag":null,"topics":["cache","cache-control","caching","etag","http","httpcache","java","spring","spring-boot","springmvc"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/galaxy-sea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-21T07:55:46.000Z","updated_at":"2023-06-30T08:26:50.000Z","dependencies_parsed_at":"2022-09-09T11:21:15.285Z","dependency_job_id":null,"html_url":"https://github.com/galaxy-sea/libby-http-cache-control","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/galaxy-sea/libby-http-cache-control","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galaxy-sea%2Flibby-http-cache-control","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galaxy-sea%2Flibby-http-cache-control/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galaxy-sea%2Flibby-http-cache-control/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galaxy-sea%2Flibby-http-cache-control/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/galaxy-sea","download_url":"https://codeload.github.com/galaxy-sea/libby-http-cache-control/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galaxy-sea%2Flibby-http-cache-control/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30428635,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T14:34:45.044Z","status":"ssl_error","status_checked_at":"2026-03-12T14:09:33.793Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cache-control","caching","etag","http","httpcache","java","spring","spring-boot","springmvc"],"created_at":"2024-09-24T14:06:48.289Z","updated_at":"2026-03-12T14:42:19.319Z","avatar_url":"https://github.com/galaxy-sea.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- TOC --\u003e\n\n- [1. HTTP cache introduction](#1-http-cache-introduction)\n- [2. Getting started](#2-getting-started)\n    - [2.1. maven dependency](#21-maven-dependency)\n- [3. Spring MVC](#3-spring-mvc)\n    - [3.1. cache-control And eTag](#31-cache-control-and-etag)\n    - [3.2. spel expressions](#32-spel-expressions)\n    - [3.3. properties](#33-properties)\n    - [3.4. support Spring Cache Abstraction](#34-support-spring-cache-abstraction)\n- [4. Spring Cloud OpenFeign clients](#4-spring-cloud-openfeign-clients)\n    - [4.1. OkHttp](#41-okhttp)\n    - [4.2. Apache HTTP](#42-apache-http)\n    - [4.3. Apache HC5](#43-apache-hc5)\n\n\u003c!-- /TOC --\u003e\n\n\n[![Maven Central](https://img.shields.io/maven-central/v/plus.wcj/libby-http-cache-control?color=3498db\u0026style=flat-square)](https://repo1.maven.org/maven2/plus/wcj/libby-http-cache-control/)\n[![JDK](https://img.shields.io/badge/JDK-1.8+-4343?style=flat-square)](https://openjdk.java.net/projects/jdk8/)\n[![Spring Boot](https://img.shields.io/badge/Spring%20Boot-2.x.x-2ecc71?style=flat-square)](https://spring.io/projects/spring-boot)\n[![Spring Cloud OpenFeign](https://img.shields.io/badge/Spring%20Cloud%20OpenFeign-3.x.x-2ecc71?style=flat-square)](https://spring.io/projects/spring-cloud-openfeign#learn)\n[![license](https://img.shields.io/github/license/galaxy-sea/libby-http-cache-control?style=flat-square)](https://www.apache.org/licenses/LICENSE-2.0)\n\n# 1. HTTP cache introduction\n\n- [HTTP caching](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching)\n- [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control)\n- [Prevent unnecessary network requests with the HTTP Cache](https://web.dev/http-cache/)\n\n# 2. Getting started\n\n## 2.1. maven dependency\n\n[![Maven Central](https://img.shields.io/maven-central/v/plus.wcj/libby-http-cache-control?style=flat-square)](https://repo1.maven.org/maven2/plus/wcj/libby-http-cache-control/)\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003eplus.wcj\u003c/groupId\u003e\n    \u003cartifactId\u003elibby-http-cache-control\u003c/artifactId\u003e\n    \u003cversion\u003e${Latest-version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n# 3. Spring MVC\n\n## 3.1. cache-control And eTag\n\n```java\n\n@RestController\n@RequestMapping\npublic class CacheController {\n    private Map\u003cString, Long\u003e data = new HashMap\u003c\u003e();\n\n    @GetMapping(\"cache/{id}\")\n    @HttpCacheControl(key = \"#id\", value = \"max-age=10, public\")\n    public Long get(@PathVariable String id) {\n        return data.computeIfAbsent(id, s -\u003e System.currentTimeMillis());\n    }\n\n    @PostMapping(\"cache/{id}\")\n    @HttpETagBind(key = \"#id\")\n    public void post(@PathVariable String id) {\n        data.put(id, System.currentTimeMillis());\n    }\n\n    @GetMapping(\"html\")\n    public ResponseEntity\u003cString\u003e html() {\n        return ResponseEntity\n                .ok()\n                .body(\"\u003c!DOCTYPE html\u003e\u003chtml\u003e\u003chead\u003e\u003cmeta charset=\\\"utf-8\\\"\u003e\u003cscript src=\\\"https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js\\\"\u003e\u003c/script\u003e\u003cscript\u003e$(document).ready(function(){$(\\\"button:nth-child(1)\\\").click(function(){$.get(\\\"./cache/1\\\",function(data,status){$(\\\"ol\\\").append(\\\"\u003cli\u003ecache1: data: \\\"+data+\\\"\u003c/li\u003e\\\")})});$(\\\"button:nth-child(2)\\\").click(function(){$.get(\\\"./cache/2\\\",function(data,status){$(\\\"ol\\\").append(\\\"\u003cli\u003ecache2: data: \\\"+data+\\\"\u003c/li\u003e\\\")})});$(\\\"button:nth-child(3)\\\").click(function(){$.post(\\\"./cache/1\\\",function(data,status){$(\\\"ol\\\").append(\\\"\u003cli\u003ecache1: modify cache1\u003c/li\u003e\\\")})});$(\\\"button:nth-child(4)\\\").click(function(){$.post(\\\"./cache/2\\\",function(data,status){$(\\\"ol\\\").append(\\\"\u003cli\u003ecache2: modify cache2\u003c/li\u003e\\\")})})});\u003c/script\u003e\u003c/head\u003e\u003cbody\u003e\u003cbutton\u003eget cache1\u003c/button\u003e\u003cbutton\u003eget cache2\u003c/button\u003e\u003cbutton\u003emodify cache1\u003c/button\u003e\u003cbutton\u003emodify cache2\u003c/button\u003e\u003col\u003e\u003cli\u003estart test\u003c/li\u003e\u003c/ol\u003e\u003c/body\u003e\u003c/html\u003e\");\n    }\n}\n```\n\n## 3.2. spel expressions\n\n1. @HttpCacheControl\n2. @HttpETagBind\n\nThe key() fields of ``@HttpCacheControl`` and ``@HttpETagBind`` support spel expressions.\nCurrently, only method parameter list is supported, Return value is not supported.\n\n## 3.3. properties\n\n```yaml\nlibby:\n  value: \"max-age=210513\"\n  max-age: 0\n  no-cache: false\n  no-store: false\n  must-revalidate: false\n  no-transform: false\n  cache-public: false\n  cache-private: false\n  proxy-revalidate: false\n  stale-while-revalidate: 0\n  stale-if-error: 0\n  s-max-age: 0\n```\n\nweight sort\n\nproperties value field ``\u003c`` properties Other fields ``\u003c`` @HttpCacheControl value field ``\u003c`` @HttpCacheControl Other fields\n\n## 3.4. support Spring Cache Abstraction\n\nsee [Cache Abstraction](https://docs.spring.io/spring-framework/docs/current/reference/html/integration.html#cache)\n\n```java\n\n@SpringBootApplication\n@EnableCaching\npublic class Application {\n    public static void main(String[] args) {\n        SpringApplication.run(Application.class, args);\n    }\n}\n```\n\n# 4. Spring Cloud OpenFeign clients\n\n| client           | support | cache type   | default cache type |\n|------------------|---------|--------------|--------------------|\n| OkHttp           | Yes     | disk         | disk               |\n| Apache HTTP      | yes     | disk, memory | memory             |\n| Apache HC5       | yes     | disk, memory | memory             |\n| ~~java.net.URL~~ | No      | -            | -                  |\n\n``java.net.URL`` is not supported because of its low performance\n\n\n## 4.1. OkHttp\n\n``` xml\n  \u003cdependency\u003e\n    \u003cgroupId\u003eio.github.openfeign\u003c/groupId\u003e\n    \u003cartifactId\u003efeign-okhttp\u003c/artifactId\u003e\n    \u003cversion\u003e${version}\u003c/version\u003e\n  \u003c/dependency\u003e\n```\n\n```yaml\nfeign:\n  okhttp:\n    enabled: true\nlibby:\n  ok-http:\n    cache-directory: \"./libby\"\n    cache-max-size: 2105131412\n```\n\n## 4.2. Apache HTTP\n\n``` xml\n  \u003cdependency\u003e\n    \u003cgroupId\u003eio.github.openfeign\u003c/groupId\u003e\n    \u003cartifactId\u003efeign-httpclient\u003c/artifactId\u003e\n    \u003cversion\u003e${version}\u003c/version\u003e\n  \u003c/dependency\u003e\n\n  \u003cdependency\u003e\n    \u003cgroupId\u003eorg.apache.httpcomponents\u003c/groupId\u003e\n    \u003cartifactId\u003ehttpclient-cache\u003c/artifactId\u003e\n    \u003cversion\u003e${version}\u003c/version\u003e\n  \u003c/dependency\u003e\n```\n\n```yaml\nfeign:\n  httpclient:\n    enabled: true\nlibby:\n  httpclient:\n    cache-type: MEMORY\n    cache-directory: \"./libby\"\n    max-object-size: 210513\n    max-cache-entries: 1412\n\n```\n\n## 4.3. Apache HC5\n\n``` xml\n  \u003cdependency\u003e\n    \u003cgroupId\u003eio.github.openfeign\u003c/groupId\u003e\n    \u003cartifactId\u003efeign-hc5\u003c/artifactId\u003e\n    \u003cversion\u003e${version}\u003c/version\u003e\n  \u003c/dependency\u003e\n\n  \u003cdependency\u003e\n    \u003cgroupId\u003eorg.apache.httpcomponents.client5\u003c/groupId\u003e\n    \u003cartifactId\u003ehttpclient5-cache\u003c/artifactId\u003e\n    \u003cversion\u003e${version}\u003c/version\u003e\n  \u003c/dependency\u003e\n```\n\n```yaml\nfeign:\n  httpclient:\n    enabled: true\nlibby:\n  httpclient5:\n    cache-type: MEMORY\n    cache-directory: \"./libby\"\n    max-object-size: 210513\n    max-cache-entries: 1412\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalaxy-sea%2Flibby-http-cache-control","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgalaxy-sea%2Flibby-http-cache-control","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalaxy-sea%2Flibby-http-cache-control/lists"}