{"id":13697516,"url":"https://github.com/rayokota/kcache","last_synced_at":"2025-05-14T12:07:15.157Z","repository":{"id":39707739,"uuid":"157827731","full_name":"rayokota/kcache","owner":"rayokota","description":"An In-Memory Cache Backed by Apache Kafka","archived":false,"fork":false,"pushed_at":"2025-04-02T13:31:05.000Z","size":1330,"stargazers_count":249,"open_issues_count":18,"forks_count":31,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-03T22:55:37.764Z","etag":null,"topics":[],"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/rayokota.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-16T07:13:54.000Z","updated_at":"2025-03-30T09:47:34.000Z","dependencies_parsed_at":"2024-01-09T08:30:57.561Z","dependency_job_id":"17604cf3-1871-459f-84ad-d0c9344a91d8","html_url":"https://github.com/rayokota/kcache","commit_stats":{"total_commits":686,"total_committers":7,"mean_commits":98.0,"dds":"0.39504373177842567","last_synced_commit":"3196e2b4b01147bd6dd79d08e18697f411ad1122"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayokota%2Fkcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayokota%2Fkcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayokota%2Fkcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayokota%2Fkcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rayokota","download_url":"https://codeload.github.com/rayokota/kcache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248341661,"owners_count":21087706,"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":[],"created_at":"2024-08-02T18:00:59.628Z","updated_at":"2025-04-11T04:27:06.162Z","avatar_url":"https://github.com/rayokota.png","language":"Java","readme":"# KCache - An In-Memory Cache Backed by Apache Kafka\n\n[![Build Status][github-actions-shield]][github-actions-link]\n[![Maven][maven-shield]][maven-link]\n[![Javadoc][javadoc-shield]][javadoc-link]\n\n[github-actions-shield]: https://github.com/rayokota/kcache/workflows/build/badge.svg?branch=master\n[github-actions-link]: https://github.com/rayokota/kcache/actions\n[maven-shield]: https://img.shields.io/maven-central/v/io.kcache/kcache.svg\n[maven-link]: https://search.maven.org/#search%7Cga%7C1%7Cio.kcache\n[javadoc-shield]: https://javadoc.io/badge/io.kcache/kcache.svg?color=blue\n[javadoc-link]: https://javadoc.io/doc/io.kcache/kcache\n\nKCache is a client library that provides an in-memory cache backed by a compacted topic in Kafka.  It is one of the patterns for using Kafka  as a persistent store, as described by Jay Kreps in the article [It's Okay to Store Data in Apache Kafka](https://www.confluent.io/blog/okay-store-data-apache-kafka/).\n\n## Maven\n\nReleases of KCache are deployed to Maven Central.\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.kcache\u003c/groupId\u003e\n    \u003cartifactId\u003ekcache\u003c/artifactId\u003e\n    \u003cversion\u003e5.2.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nFor Java 11 or above, use `5.x` otherwise use `4.x`.\n\n## Usage\n\nAn instance of `KafkaCache` implements the `java.util.SortedMap` interface.  Here is an example usage:\n\n```java\nimport io.kcache.*;\n\nString bootstrapServers = \"localhost:9092\";\nCache\u003cString, String\u003e cache = new KafkaCache\u003c\u003e(\n    bootstrapServers,\n    Serdes.String(),  // for serializing/deserializing keys\n    Serdes.String()   // for serializing/deserializing values\n);\ncache.init();   // creates topic, initializes cache, consumer, and producer\ncache.put(\"Kafka\", \"Rocks\");\nString value = cache.get(\"Kafka\");  // returns \"Rocks\"\ncache.remove(\"Kafka\");\ncache.close();  // shuts down the cache, consumer, and producer\n```\n\nOne can also use RocksDB to back the `KafkaCache`:\n\n```java\nProperties props = new Properties();\nprops.put(KafkaCacheConfig.KAFKACACHE_BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);\nprops.put(KafkaCacheConfig.KAFKACACHE_BACKING_CACHE_CONFIG, \"rocksdb\");\nprops.put(KafkaCacheConfig.KAFKACACHE_DATA_DIR_CONFIG, \"/tmp\");\nCache\u003cString, String\u003e cache = new KafkaCache\u003c\u003e(\n    new KafkaCacheConfig(props),\n    Serdes.String(),  // for serializing/deserializing keys\n    Serdes.String()   // for serializing/deserializing values\n);\ncache.init();\n```\n## Basic Configuration\n\nKCache has a number of configuration properties that can be specified.\n\n- `kafkacache.bootstrap.servers` - A list of host and port pairs to use for establishing the initial connection to Kafka.\n- `kafkacache.group.id` - The group ID to use for the internal consumer.  Defaults to `kafkacache`.\n- `kafkacache.client.id` - The client ID to use for the internal consumer.  Defaults to `kafka-cache-reader-\u003ctopic\u003e`.\n- `kafkacache.topic` - The name of the compacted topic.  Defaults to `_cache`.\n- `kafkacache.topic.replication.factor` - The desired replication factor for the compacted topic.  Defaults to 3.\n- `kafkacache.topic.num.partitions` - The desired number of partitions for for the compacted topic.  Defaults to 1.\n- `kafkacache.topic.partitions` - A list of partitions to consume, or all partitions if not specified.\n- `kafkacache.topic.partitions.offset` - The offset to start consuming all partitions from, one of `beginning`, `end`, \n   a positive number representing an absolute offset, a negative number representing a relative offset from the end, \n   or `@\u003cvalue\u003e`, where `\u003cvalue\u003e` is a timestamp in ms.  Defaults to `beginning`.\n- `kafkacache.init.timeout.ms` - The timeout for initialization of the Kafka cache, including creation of the compacted topic.  Defaults to 300 seconds.\n- `kafkacache.timeout.ms` - The timeout for an operation on the Kafka cache.  Defaults to 60 seconds.\n- `kafkacache.backing.cache` - The backing cache for KCache, one of `memory` (default), `bdbje`, `caffeine`, `lmdb`, `mapdb`, `rdbms`, or `rocksdb`.\n- `kafkacache.data.dir` - The root directory for backing cache storage.  Defaults to `/tmp`.\n\nConfiguration properties can be passed as follows:\n\n```java\nProperties props = new Properties();\nprops.setProperty(\"kafkacache.bootstrap.servers\", \"localhost:9092\");\nprops.setProperty(\"kafkacache.topic\", \"_mycache\");\nCache\u003cString, String\u003e cache = new KafkaCache\u003c\u003e(\n    new KafkaCacheConfig(props),\n    Serdes.String(),  // for serializing/deserializing keys\n    Serdes.String()   // for serializing/deserializing values\n);\ncache.init();\n...\n```\n\n## Security\n\nKCache supports both SSL authentication and SASL authentication to a secure Kafka cluster.  See the [JavaDoc](https://static.javadoc.io/io.kcache/kcache/latest/io/kcache/KafkaCacheConfig.html) for more information.\n\n## Using KCache as a Replicated Cache\n\nKCache can be used as a replicated cache, with some caveats.  To ensure that updates are processed in the proper order, one instance of KCache should be designated as the sole writer, with all writes being forwarded to it.  If the writer fails, another instance can then be elected as the new writer.  \n\nFor an example of a highly-available service that wraps KCache, see [Keta](https://github.com/rayokota/keta).\n","funding_links":[],"categories":["Libraries","缓存库","Projects built on top of Kafka","\u003ca name=\"Java\"\u003e\u003c/a\u003eJava"],"sub_categories":["Kafka","Integrations"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayokota%2Fkcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frayokota%2Fkcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayokota%2Fkcache/lists"}