{"id":16420294,"url":"https://github.com/newpanjing/group-cache","last_synced_at":"2026-02-22T04:32:46.045Z","repository":{"id":66097522,"uuid":"65064812","full_name":"newpanjing/group-cache","owner":"newpanjing","description":"简单的内存缓存实现，实现group概念，一个group里面是个有序的集合，集合支持key-value expire弥补redis list的不足","archived":false,"fork":false,"pushed_at":"2022-02-16T13:30:51.000Z","size":16,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-25T07:13:36.329Z","etag":null,"topics":["cache","group-cache","java-cache"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/newpanjing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2016-08-06T04:25:03.000Z","updated_at":"2023-08-26T21:27:22.000Z","dependencies_parsed_at":"2023-03-07T11:01:11.131Z","dependency_job_id":null,"html_url":"https://github.com/newpanjing/group-cache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/newpanjing/group-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newpanjing%2Fgroup-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newpanjing%2Fgroup-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newpanjing%2Fgroup-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newpanjing%2Fgroup-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/newpanjing","download_url":"https://codeload.github.com/newpanjing/group-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newpanjing%2Fgroup-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29704796,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T03:17:42.375Z","status":"ssl_error","status_checked_at":"2026-02-22T03:17:31.622Z","response_time":110,"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","group-cache","java-cache"],"created_at":"2024-10-11T07:27:33.751Z","updated_at":"2026-02-22T04:32:46.010Z","avatar_url":"https://github.com/newpanjing.png","language":null,"readme":"# group-cache\n简单的内存缓存实现，实现`group`概念，一个`group`里面是个有序的集合，集合支持`key-value`、`expire`弥补redis list的不足\n\n## 总共有3个类：\n\n- `GroupCacheFactory` 工厂用于获取Group\n- `Group` 组，存放多个key和value\n- `CacheEntity` 缓存实体，所有缓存的数据都是以CacheEntity为载体放入Group中\n\n## 博客\n[https://www.88cto.com](https://www.88cto.com)\n\n## 测试代码： \n\n```java\npackage com.qikenet.cache;\n\nimport java.util.Random;\n\npublic class CacheTest {\n\n\tpublic static void main(String[] args) {\n\t\t/**\n\t\t * 概念：\n\t\t * 组缓存，在传统redis、memcached 这一类的缓存容器中，都是key-value类型的\n\t\t * 所谓的组缓存，就是在key-value的外层加一个标识\n\t\t * 用list来做比较，在redis中，list的结构是这样的，并且list的某一项不能设置存活时间：\n\t\t * \tabc\n\t\t * \t\t1\n\t\t * \t\t2\n\t\t * \t\t3\n\t\t * \n\t\t * 在GroupCache中结构是这样的\t:\n\t\t * abc\n\t\t * \ta 1 10\n\t\t *  b 2 5\n\t\t *  c 3 1\n\t\t * 第一行：a代表key，1代表value，10代表存活10秒，存活时间以秒为单位\t\t \n\t\t */\n\t\t\n\t\t//创建一个工厂，暂时不支持持久化\n\t\tGroupCacheFactory factory=new GroupCacheFactory();\n\t\t//获取一个组\n\t\tGroup group1=factory.group(\"group1\");\n\t\tgroup1.push(\"a\", 123);//默认永久存活\n\t\tgroup1.push(\"b\", 321, 10);//存活10秒\n\t\t\n\t\t//查看还有多久失效\n\t\tSystem.out.println(\"group 1 的元素b 剩余失效时间：\"+group1.ttl(\"b\"));\n\t\t\n\t\t//检测值是否存在\n\t\tSystem.out.println(\"a是否存在：\"+group1.exist(\"a\"));\n\t\tSystem.out.println(\"c是否存在：\"+group1.exist(\"c\"));\n\t\t\n\t\t//获取有效的key\n\t\tSystem.out.println(\"group1 keys:\"+group1.getKeys());\n\t\t\n\t\t//获取有效的value\n\t\tSystem.out.println(\"group1 values:\"+group1.getValues());\n\t\t\n\t\t//通过key获取值\n\t\tSystem.out.println(\"通过a获取：\"+group1.getValue(\"a\"));\n\t\t\n\t\t\n\t\t//获取一个组，并设置容量为100，默认容量为1000,不同的group中数据不能共享\n\t\tGroup group2=factory.group(\"group2\",100);\n\t\t\n\t\t//如果push的数据大于容量，则会丢弃\n\t\tfor(int i=0;i\u003c101;i++){\n\t\t\tgroup2.push(String.valueOf(i), i, new Random().nextInt(10));\n\t\t}\n\t\t//获取存活的元素的数量\n\t\tSystem.out.println(\"group2大小:\"+group2.size());\n\t\t\n\t\t//设置元素的存活时间\n\t\tgroup2.expire(\"2\", 100);\n\t\t\n\t\t//删除一个元素\n\t\tgroup2.delete(\"3\");\n\t\tSystem.out.println(\"group删除后的元素大小：\"+group2.size());\n\t\t\n\t\t//获取group容量大小\n\t\tSystem.out.println(\"group2容量：\"+group2.getCapacity());\n\t\t\n\t\tSystem.out.println(group2.getKeys());\n\t\t\n\t}\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnewpanjing%2Fgroup-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnewpanjing%2Fgroup-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnewpanjing%2Fgroup-cache/lists"}