{"id":13597485,"url":"https://github.com/alibaba/jetcache","last_synced_at":"2025-05-15T00:00:37.211Z","repository":{"id":37706376,"uuid":"88024517","full_name":"alibaba/jetcache","owner":"alibaba","description":"JetCache is a Java cache framework.","archived":false,"fork":false,"pushed_at":"2025-04-28T05:32:38.000Z","size":3843,"stargazers_count":5351,"open_issues_count":414,"forks_count":1067,"subscribers_count":173,"default_branch":"master","last_synced_at":"2025-05-07T23:29:42.501Z","etag":null,"topics":["cache","java","jcache","redis","spring","spring-cache"],"latest_commit_sha":null,"homepage":"","language":"Java","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/alibaba.png","metadata":{"files":{"readme":"readme.MD","changelog":"changelog.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-04-12T07:48:23.000Z","updated_at":"2025-05-07T06:34:25.000Z","dependencies_parsed_at":"2023-02-03T18:45:45.540Z","dependency_job_id":"8e2abab5-6b36-4f32-bfe1-f7ac0daaf80f","html_url":"https://github.com/alibaba/jetcache","commit_stats":{"total_commits":1205,"total_committers":34,"mean_commits":35.44117647058823,"dds":"0.052282157676348584","last_synced_commit":"dddd0313194031a1650519d3753fbda5b5c94150"},"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2Fjetcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2Fjetcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2Fjetcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2Fjetcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alibaba","download_url":"https://codeload.github.com/alibaba/jetcache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254249199,"owners_count":22039029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","java","jcache","redis","spring","spring-cache"],"created_at":"2024-08-01T17:00:34.341Z","updated_at":"2025-05-15T00:00:37.068Z","avatar_url":"https://github.com/alibaba.png","language":"Java","readme":"[![Java CI with Maven](https://github.com/alibaba/jetcache/actions/workflows/maven.yml/badge.svg)](https://github.com/alibaba/jetcache/actions/workflows/maven.yml)\n[![Coverage Status](https://coveralls.io/repos/github/alibaba/jetcache/badge.svg?branch=master)](https://coveralls.io/github/alibaba/jetcache?branch=master)\n[![GitHub release](https://img.shields.io/github/release/alibaba/jetcache.svg)](https://github.com/alibaba/jetcache/releases)\n[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)\n\n# Introduction\nJetCache is a Java cache abstraction which provides uniform usage for different caching solutions. \nIt provides more powerful annotations than those in Spring Cache. The annotations in JetCache supports native TTL, \ntwo level caching, and automatically refresh in distrubuted environments, also you can manipulate ```Cache``` instance by your code. \nCurrently, there are four implementations: ```RedisCache```, ```TairCache```(not open source on github), ```CaffeineCache``` (in memory) and a simple ```LinkedHashMapCache``` (in memory).\nFull features of JetCache:\n* Manipulate cache through uniform Cache API. \n* Declarative method caching using annotations with TTL(Time To Live) and two level caching support\n* Create \u0026 configure ```Cache``` instance with cache manager\n* Automatically collect access statistics for ```Cache``` instance and method level cache\n* The strategy of key generation and value serialization can be customized\n* Cache key convertor supported: ```fastjson```/```fastjson2```/```jackson```; Value convertor supported: ```java```/```kryo```/```kryo5```\n* Distributed cache auto refresh and distributed lock. (2.2+)\n* Asynchronous access using Cache API (2.2+, with redis lettuce client)\n* Invalidate local caches (in all JVM process) after updates (2.7+)\n* Spring Boot support\n\nrequirements:\n* JDK1.8\n* Spring Framework4.0.8+ (optional, with annotation support)，jetcache 2.7 need 5.2.4+\n* Spring Boot1.1.9+ (optional), jetcache 2.7 need 2.2.5+\n\nVisit [docs](docs/EN/Readme.md) for more details.\n\n# Getting started\n\n## Method cache\nDeclare method cache using ```@Cached``` annotation.  \n```expire = 3600``` indicates that the elements will expire in 3600 seconds after being set.\nJetCache automatically generates the cache key with all the parameters.\n```java\npublic interface UserService {\n    @Cached(expire = 3600, cacheType = CacheType.REMOTE)\n    User getUserById(long userId);\n}\n```\n\nUsing ```key``` attribute to specify cache key using [SpEL](https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/expressions.html) script.\n```java\npublic interface UserService {\n    @Cached(name=\"userCache-\", key=\"#userId\", expire = 3600)\n    User getUserById(long userId);\n\n    @CacheUpdate(name=\"userCache-\", key=\"#user.userId\", value=\"#user\")\n    void updateUser(User user);\n\n    @CacheInvalidate(name=\"userCache-\", key=\"#userId\")\n    void deleteUser(long userId);\n}\n```\nIn order to use parameter name such as ```key=\"#userId\"```, you javac compiler target must be 1.8 and above, and the ```-parameters``` should be set. Otherwise, use index to access parameters like ```key=\"args[0]\"```\n\nAuto refreshment:\n```java\npublic interface SummaryService{\n    @Cached(expire = 3600, cacheType = CacheType.REMOTE)\n    @CacheRefresh(refresh = 1800, stopRefreshAfterLastAccess = 3600, timeUnit = TimeUnit.SECONDS)\n    @CachePenetrationProtect\n    BigDecimal summaryOfToday(long categoryId);\n}\n```\nCachePenetrationProtect annotation indicates that the cache will be loaded synchronously in multi-thread environment.\n\n## Cache API\nCreate a ```Cache``` instance with ```CacheManager```:\n\n```java\n@Autowired\nprivate CacheManager cacheManager;\nprivate Cache\u003cString, UserDO\u003e userCache;\n\n@PostConstruct\npublic void init() {\n    QuickConfig qc = QuickConfig.newBuilder(\"userCache\")\n        .expire(Duration.ofSeconds(100))\n        .cacheType(CacheType.BOTH) // two level cache\n        .localLimit(50)\n        .syncLocal(true) // invalidate local cache in all jvm process after update\n        .build();\n    userCache = cacheManager.getOrCreateCache(qc);\n}\n```\nThe code above create a ```Cache``` instance. ```cacheType = CacheType.BOTH``` define a two level cache (a local in-memory-cache and a remote cache system) with local elements limited upper to 50(LRU based evict). You can use it like a map: \n```java\nUserDO user = userCache.get(12345L);\nuserCache.put(12345L, loadUserFromDataBase(12345L));\nuserCache.remove(12345L);\n\nuserCache.computeIfAbsent(1234567L, (key) -\u003e loadUserFromDataBase(1234567L));\n```\n\n## Advanced API\nAsynchronous API:\n```java\nCacheGetResult r = cache.GET(userId);\nCompletionStage\u003cResultData\u003e future = r.future();\nfuture.thenRun(() -\u003e {\n    if(r.isSuccess()){\n        System.out.println(r.getValue());\n    }\n});\n```\n\nDistributed lock:\n```java\ncache.tryLockAndRun(\"key\", 60, TimeUnit.SECONDS, () -\u003e heavyDatabaseOperation());\n```\n\nRead through and auto refresh:\n```java\n@Autowired\nprivate CacheManager cacheManager;\nprivate Cache\u003cString, Long\u003e orderSumCache;\n\n@PostConstruct\npublic void init() {\n    QuickConfig qc = QuickConfig.newBuilder(\"userCache\")\n        .expire(Duration.ofSeconds(3600))\n        .loader(this::loadOrderSumFromDatabase)\n        .refreshPolicy(RefreshPolicy.newPolicy(60, TimeUnit.SECONDS).stopRefreshAfterLastAccess(100, TimeUnit.SECONDS))\n        .penetrationProtect(true)\n        .build();\n    orderSumCache = cacheManager.getOrCreateCache(qc);\n}\n```\n\n## Configuration with Spring Boot\n\npom:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.alicp.jetcache\u003c/groupId\u003e\n    \u003cartifactId\u003ejetcache-starter-redis\u003c/artifactId\u003e\n    \u003cversion\u003e${jetcache.latest.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nApp class:\n```java\n@SpringBootApplication\n@EnableMethodCache(basePackages = \"com.company.mypackage\")\n@EnableCreateCacheAnnotation // deprecated in jetcache 2.7, can be removed if @CreateCache is not used\npublic class MySpringBootApp {\n    public static void main(String[] args) {\n        SpringApplication.run(MySpringBootApp.class);\n    }\n}\n```\n\nspring boot application.yml config:\n```yaml\njetcache:\n  statIntervalMinutes: 15\n  areaInCacheName: false\n  local:\n    default:\n      type: linkedhashmap #other choose：caffeine\n      keyConvertor: fastjson2 #other choose：fastjson/jackson\n      limit: 100\n  remote:\n    default:\n      type: redis\n      keyConvertor: fastjson2 #other choose：fastjson/jackson\n      broadcastChannel: projectA\n      valueEncoder: java #other choose：kryo/kryo5\n      valueDecoder: java #other choose：kryo/kryo5\n      poolConfig:\n        minIdle: 5\n        maxIdle: 20\n        maxTotal: 50\n      host: ${redis.host}\n      port: ${redis.port}\n```\n\u003e Visit [detail configuration](docs/EN/Config.md) for more instructions\n## More docs\nVisit [docs](docs/EN/Readme.md) for more details.\n\nFor upgrade see [changelog](https://github.com/alibaba/jetcache/wiki/Changelog) and [compatibility notes](docs/EN/Compatibility.md).\n","funding_links":[],"categories":["Java","常用框架\\\u0026第三方库","缓存库"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falibaba%2Fjetcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falibaba%2Fjetcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falibaba%2Fjetcache/lists"}