{"id":13610894,"url":"https://github.com/mori-atsushi/kotlin-cacheable","last_synced_at":"2025-04-13T01:33:21.870Z","repository":{"id":205212814,"uuid":"713685225","full_name":"mori-atsushi/kotlin-cacheable","owner":"mori-atsushi","description":"An annotation-based caching library for Kotlin Multiplatform","archived":false,"fork":false,"pushed_at":"2025-03-06T10:17:21.000Z","size":322,"stargazers_count":101,"open_issues_count":11,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-06T11:27:05.457Z","etag":null,"topics":["kotlin-compiler-plugin","kotlin-multiplatform"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/mori-atsushi.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":"2023-11-03T03:01:23.000Z","updated_at":"2025-03-05T21:29:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"2802da0a-6984-4919-82fc-6badb83a9662","html_url":"https://github.com/mori-atsushi/kotlin-cacheable","commit_stats":null,"previous_names":["mori-atsushi/kotlin-cacheable"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mori-atsushi%2Fkotlin-cacheable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mori-atsushi%2Fkotlin-cacheable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mori-atsushi%2Fkotlin-cacheable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mori-atsushi%2Fkotlin-cacheable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mori-atsushi","download_url":"https://codeload.github.com/mori-atsushi/kotlin-cacheable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654037,"owners_count":21140236,"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":["kotlin-compiler-plugin","kotlin-multiplatform"],"created_at":"2024-08-01T19:01:49.144Z","updated_at":"2025-04-13T01:33:21.548Z","avatar_url":"https://github.com/mori-atsushi.png","language":"Kotlin","funding_links":[],"categories":["Libraries","缓存库","Kotlin"],"sub_categories":["📦 Storage"],"readme":"# Kotlin Cacheable\n\nKotlin Cacheable is an annotation-based caching library for Kotlin Multiplatform.\n\n## Setup\n\nThis library is published to Maven Central.\nAdd the Maven Central repository to your project's `pluginManagement` and\n`dependencyResolutionManagement` sections.\n\n```kotlin\n// setting.gradle.kts\npluginManagement {\n    repositories {\n        mavenCentral()\n    }\n}\ndependencyResolutionManagement {\n    repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)\n    repositories {\n        mavenCentral()\n    }\n}\n```\n\nEnable the Gradle plugin for the module where you want to use this library.\n\n```kotlin\n// build.gradle.kts\nplugins {\n    kotlin(/* ... */)\n    id(\"com.moriatsushi.cacheable\") version \"0.0.3\"\n}\n```\n\nYou also need to add the `cacheable-core` dependency to the module.\n\n```kotlin\n// build.gradle.kts\ndependencies {\n    implementation(\"com.moriatsushi.cacheable:cacheable-core:0.0.3\")\n}\n```\n\n## Basic Usage\n\nYou can use `@Cacheable` annotation to cache the result of specified functions.\nWhen you call a function with this annotation, it will return the cached value if the function is\ncalled with the same arguments.\n\nHere is an example:\n\n```kotlin\n@Cacheable\nfun getSomething(key: String): Something {\n    /* ... */\n}\n```\n\nThis is equivalent to the following code:\n\n```kotlin\nprivate var cache = mutableMapOf\u003cString, Something\u003e()\n\nfun getSomething(key: String): Something =\n    cache.getOrPut(key) { /* ... */ }\n```\n\nIf you use the cacheable function within a class, the cache is only shared within an instance of the\nclass.\n\nYou can also use `@Cacheable` annotation for a suspend function.\n\n```kotlin\nclass Repository(private val api: Api) {\n    @Cacheable\n    suspend fun getUser(id: String): User =\n        api.getUser(id)\n}\n```\n\n## APIs\nThere are 2 parameters you can specify to `@Cacheable` annotation.\n\n* `maxCount`: The maximum number of cached values. If the number of cached values exceeds this\n  value, the cache with the oldest access time will be removed. If you don't specify this parameter,\n  the number of cached values will be unlimited.\n* `lock`: When this is `true`, the function is guaranteed to be called only once even if the\n  function is called multiple times with the same arguments at the same time. Otherwise, the\n  function may be called multiple times with the same arguments at the same time. The default value\n  is false.\n\n```kotlin\nclass SomeClass {\n    @Cacheable(maxCount = 10, lock = true)\n    fun getSomething(key: String): Something {\n        // ...\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmori-atsushi%2Fkotlin-cacheable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmori-atsushi%2Fkotlin-cacheable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmori-atsushi%2Fkotlin-cacheable/lists"}