{"id":24844251,"url":"https://github.com/infotechbridge/anycache","last_synced_at":"2025-10-27T01:03:44.396Z","repository":{"id":33448880,"uuid":"157322071","full_name":"InfoTechBridge/AnyCache","owner":"InfoTechBridge","description":".Net cache framework for connecting to any caches including in memory cache and Redis from dotnet, dotnet-core and Xamarin forms.","archived":false,"fork":false,"pushed_at":"2022-12-08T01:40:48.000Z","size":56,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T08:17:59.990Z","etag":null,"topics":["cache","cross-platform","diskcache","dotnet","dotnet-core","inmemory-cache","json","memorycache","msgpack","protobuf","redis","xamarin-forms"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/InfoTechBridge.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}},"created_at":"2018-11-13T04:52:01.000Z","updated_at":"2024-04-27T18:31:58.000Z","dependencies_parsed_at":"2023-01-15T00:58:11.359Z","dependency_job_id":null,"html_url":"https://github.com/InfoTechBridge/AnyCache","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/InfoTechBridge%2FAnyCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InfoTechBridge%2FAnyCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InfoTechBridge%2FAnyCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InfoTechBridge%2FAnyCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InfoTechBridge","download_url":"https://codeload.github.com/InfoTechBridge/AnyCache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236489531,"owners_count":19157013,"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","cross-platform","diskcache","dotnet","dotnet-core","inmemory-cache","json","memorycache","msgpack","protobuf","redis","xamarin-forms"],"created_at":"2025-01-31T09:17:09.633Z","updated_at":"2025-10-14T16:30:53.814Z","avatar_url":"https://github.com/InfoTechBridge.png","language":"C#","readme":"# AnyCache\n.Net cache framework for connecting to any caches including In Memory cache and Redis from dotnet, dotnet-core and Xamarin forms.\n\n[![License](http://img.shields.io/:license-MIT-blue.svg)](https://raw.githubusercontent.com/giacomelli/JobSharp/master/LICENSE)\n\nAnyCache is library for having common cache API for .Net framework and .Net Core as well as Xamarin Forms projects.\nAs you know, the MemoryCache API in .Net freamwork is not same as MemoryCache in .Net Core and we couldn't easly transfer our code between them. By AnyCache we could have one code base that could be reused in diffrent type of projects without any code change.\nAnyCache also support Redis cache whith same API as MemoryCache, so we could swap our project caching from MemoryCache to Redis cache and vice versa whithout any major code change. I have plan to add more type of chaching in the future.\n\nFeatures\n===\n- Same API for .Net Framework, .Net Core projects and Xamarin Forms projects\n- Same API for any type of caching including In Memory cache and Redis cache.\n\nBasic usage\n------\n\n```csharp\ncache.Set(\"key\", 123000);\nvar ret = cache.Get\u003cint?\u003e(\"key\");\n```\n\n```csharp\nPerson obj = new Person(\"Tom\", \"Hanks\");\ncache.Set(key, obj);\n\nPerson ret = cache.Get\u003cPerson\u003e(key);\n```\n\nInstallation\n-------------\n\nAnyCache is available as a nuget package and supports In Memory and Redis cache at the moment.\n\n**In Memory Cache**\n\nFor creating in memory cache use following nuget command to add library to your project:\n\n```\nPM\u003e Install-Package AnyCache.InMemory\n```\n\nThen use following code to create In Memory cache instance. \n\n```csharp\nvar cache = new InMemoryCache();\n```\n\n**Redis Cache**\n\nFor creating Redis cache use following nuget command to add library to your project:\n\n```\nPM\u003e Install-Package AnyCache.Redis\nPM\u003e Install-Package AnyCache.Serialization\n```\n\nThen use following code to create Redis cache instance. \n\n```csharp\nISerializer serializer = new JsonSerializer(null, true);\nvar cache = new RedisCache(connectionString:\"localhost\", serializer:serializer);\n```\n\nDependency Injection\n--------------------\n\nAnyCache supports Dependency Injection. Following example shows how to use AnyCache by .Net Core injection mechanism.\n\n**In Memory Cache**\n\nRemember to register InMemoryCache as singleton to make sure using same cache instance in whole of your project.\n\n```csharp\nservice.AddSingleton\u003cIAnyCache\u003e(s =\u003e\n{\n    return new InMemoryCache();;\n});\n```\n\n**Redis Cache**\n\n```csharp\nservice.AddSingleton\u003cIAnyCache\u003e(s =\u003e\n{\n    ISerializer serializer = new JsonSerializer(null, true);\n    return new RedisCache(connectionString:\"localhost\", serializer:serializer);\n});\n```\n\nNow you can inject AnyCache at runtime into your services/controllers:\n\n```csharp\npublic class EmployeesController \n{\n    private readonly IAnyCache _cache;\n\n    public EmployeesController(IAnyCache cache)\n    {\n        _cache = cache;\n    }\n\n    // use _cache.Set or _cache.Get\n}\n```\n\nList of available methods\n-------------------------\n\n```csharp\nobject this[string key] { get; set; }\n\nbool Add(string key, object value, DateTimeOffset? absoluteExpiration = null);\nbool Add\u003cT\u003e(string key, T value, DateTimeOffset? absoluteExpiration = null);\nbool Add(string key, object value, TimeSpan slidingExpiration);        \nbool Add\u003cT\u003e(string key, T value, TimeSpan slidingExpiration);        \n\nvoid Set(string key, object value, DateTimeOffset? absoluteExpiration = null);\nvoid Set\u003cT\u003e(string key, T value, DateTimeOffset? absoluteExpiration = null);\nvoid Set(string key, object value, TimeSpan slidingExpiration);\nvoid Set\u003cT\u003e(string key, T value, TimeSpan slidingExpiration);\n\nbool Contains(string key);\n\nobject Get(string key);\nT Get\u003cT\u003e(string key);\n\nT GetValueOrDefault\u003cT\u003e(string key, T value);\n\nTask\u003cobject\u003e GetAsync(string key);\nTask\u003cT\u003e GetAsync\u003cT\u003e(string key);\n\nobject GetValueOrAdd(string key, object value, DateTimeOffset? absoluteExpiration = null);\nT GetValueOrAdd\u003cT\u003e(string key, T value, DateTimeOffset? absoluteExpiration = null);\nobject GetValueOrAdd(string key, object value, TimeSpan slidingExpiration);\nT GetValueOrAdd\u003cT\u003e(string key, T value, TimeSpan slidingExpiration);\n\nobject GetValueOrAdd(string key, Func\u003cobject\u003e retriever, DateTimeOffset? absoluteExpiration = null);\nT GetValueOrAdd\u003cT\u003e(string key, Func\u003cT\u003e retriever, DateTimeOffset? absoluteExpiration = null);\nobject GetValueOrAdd(string key, Func\u003cobject\u003e retriever, TimeSpan slidingExpiration);\nT GetValueOrAdd\u003cT\u003e(string key, Func\u003cT\u003e retriever, TimeSpan slidingExpiration);\n\nIEnumerable\u003cKeyValuePair\u003cstring, object\u003e\u003e GetAll(IEnumerable\u003cstring\u003e keys);\nIEnumerable\u003cKeyValuePair\u003cstring, T\u003e\u003e GetAll\u003cT\u003e(IEnumerable\u003cstring\u003e keys);\n\nobject Remove(string key);\nT Remove\u003cT\u003e(string key);\n\nlong GetCount();\n\nIEnumerator\u003cKeyValuePair\u003cstring, object\u003e\u003e GetEnumerator();\n        \nvoid ClearCache();\nvoid Compact();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfotechbridge%2Fanycache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfotechbridge%2Fanycache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfotechbridge%2Fanycache/lists"}