{"id":22244565,"url":"https://github.com/dvlkv/cacheit","last_synced_at":"2025-07-28T02:32:26.990Z","repository":{"id":111223683,"uuid":"146397914","full_name":"dvlkv/CacheIt","owner":"dvlkv","description":"CacheIt makes caching in your application easier","archived":false,"fork":false,"pushed_at":"2018-08-28T11:27:40.000Z","size":19,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-13T04:54:42.044Z","etag":null,"topics":["asp-net-core","caching","dotnet","dotnet-core","json","memory-cache","message-pack","redis"],"latest_commit_sha":null,"homepage":"","language":"C#","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/dvlkv.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":"2018-08-28T05:48:52.000Z","updated_at":"2020-02-18T02:01:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"26f6f722-502c-40f1-863e-26562953f021","html_url":"https://github.com/dvlkv/CacheIt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvlkv%2FCacheIt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvlkv%2FCacheIt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvlkv%2FCacheIt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvlkv%2FCacheIt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dvlkv","download_url":"https://codeload.github.com/dvlkv/CacheIt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227857350,"owners_count":17830167,"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":["asp-net-core","caching","dotnet","dotnet-core","json","memory-cache","message-pack","redis"],"created_at":"2024-12-03T04:37:25.541Z","updated_at":"2024-12-03T04:37:26.161Z","avatar_url":"https://github.com/dvlkv.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CacheIt\nCacheIt makes caching in your app better - you don't need to write many lines of boilerplate\n\n## Usage\n### Default caching implementation\n```c#\npublic interface IService\n{\n    string CachedFunction();\n    Task\u003cstring\u003e AsyncCachedFunction();\n}\n\npublic class ServiceImplementation : IService\n{    \n    public string CachedFunction()\n    {\n        var entry = _cache.Get(GetKey());\n        if (entry != null)\n            return entry;\n        \n        var result = \"test\";\n        _cache.Set(result);\n        \n        return result;\n    }\n\n    public async Task\u003cstring\u003e AsyncCachedFunction()\n    {\n        var entry = _cache.Get(GetKey());\n        if (entry != null)\n            return entry;\n        \n        var result = \"async test\";\n        _cache.Set(result);\n        \n        return result;\n    }\n}\n```\n### Caching implementation with CacheIt\n```c#\npublic interface IService\n{\n    [Cached]\n    string CachedFunction();\n    [Cached]\n    Task\u003cstring\u003e AsyncCachedFunction();\n}\n\npublic class ServiceImplementation : IService\n{    \n   public string CachedFunction()\n   {\n        return \"test\";\n   }\n\n   public async Task\u003cstring\u003e AsyncCachedFunction()\n   {\n       return \"async test\";\n   }\n}\n```\n## Setup\nNow CacheIt supports IDistributedCache and IMemoryCache\nTo make it work, you should install CacheIt.DistributedCache or CacheIt.MemoryCache\n\nNow you should add this to your Startup.cs:\n```c#\nservices.AddDistributedCachable();\n```\nor\n```c#\nservices.AddMemoryCachable();\n```\n\nIf you use distributed cache, you need to add entry serializer:\n```c#\nservices.AddJsonEntrySerializer();\n```\nor\n```c#\nservices.AddMessagePackEntrySerializer();\n```\n#\nThen you should decorate your services to enable caching in them, it's easy:\nUse\n```c#\nservices.AddCachable\u003cIService, ServiceImplementation\u003e();\n```\nInstead of\n```c#\nservices.AddScoped\u003cIService, ServiceImplementation\u003e();\n```\n## Configuration\nYou can configure cache entries like\n```c#\nservices.AddMemoryCachable(opts =\u003e \n{\n    opts.ConfigureAll(entryOptions =\u003e { ... });\n    opts.Configure\u003cTResult\u003e(entryOptions =\u003e { ... });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvlkv%2Fcacheit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdvlkv%2Fcacheit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvlkv%2Fcacheit/lists"}