{"id":27026958,"url":"https://github.com/intelligenthack/intelligentcache","last_synced_at":"2025-04-04T23:16:39.352Z","repository":{"id":45166145,"uuid":"286696500","full_name":"intelligenthack/intelligentcache","owner":"intelligenthack","description":"A distributed cache backed by Redis","archived":false,"fork":false,"pushed_at":"2023-07-05T14:48:58.000Z","size":207,"stargazers_count":18,"open_issues_count":5,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-13T03:38:25.186Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/intelligenthack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2020-08-11T09:02:32.000Z","updated_at":"2024-06-19T14:19:59.000Z","dependencies_parsed_at":"2023-01-20T16:00:47.453Z","dependency_job_id":null,"html_url":"https://github.com/intelligenthack/intelligentcache","commit_stats":null,"previous_names":["intelligenthack/distributed-cache"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intelligenthack%2Fintelligentcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intelligenthack%2Fintelligentcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intelligenthack%2Fintelligentcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intelligenthack%2Fintelligentcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/intelligenthack","download_url":"https://codeload.github.com/intelligenthack/intelligentcache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261586,"owners_count":20910108,"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":"2025-04-04T23:16:38.871Z","updated_at":"2025-04-04T23:16:39.347Z","avatar_url":"https://github.com/intelligenthack.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"doc/logo.png?raw=true\" width=\"200\"\u003e\r\n\r\n# Intelligent Cache\r\n\r\nThis package implements a distributed cache monad (\"pattern\") and currently supports single and multiple layers of caching, in memory and via Redis.\r\n\r\nTo use the pattern, you will interact with an object of type ICache, where you can use the following operations:\r\n\r\n```c#\r\n// Get something from the cache, on cache fail the Func is called to refresh the value and stored\r\nvar foo = myCache.GetSet(\"foo-cache-key\", ()=\u003e{ return foo-from-db(); }, Timespan.FromHours(1) );\r\n\r\n// alternatively\r\n\r\n// Invalidate the cache, in case we've modified foo in the db so the cache is stale\r\nmyCache.Invalidate(\"foo-cache-key\");\r\n\r\n```\r\n\r\nThe `ICache` object can be of different kinds -- we currently offer a memory cache for local caching and a Redis cache for distributed caching. What makes the pattern a monad is that different caches can be *composed* and this allows seamless multilayer caching.\r\n\r\nFor example, to implement a multilayer cache with a local layer and a Redis layer:\r\n\r\n```c#\r\nvar memoryCache = new MemoryCache(/* params */);\r\nvar redisCache = new RedisCache(/* params */);\r\nvar cache = new CompositeCache(memoryCache, redisCache);\r\n```\r\n\r\nNote that this cache does not invalidate correctly in a web farm environment: Invalidations will work on the local server and Redis but not the other web farm webservers. In order to propagate invalidation, we introduced two new composable ICache objects: `RedisInvalidationSender` and `RedisInvalidationReceiver`.\r\n\r\nIn order to create a local cache that invalidates when the remote cache is nuked, you can follow this composition pattern:\r\n\r\n```c#\r\nISubscriber subscriber = GetRedisSubscriber();\r\nvar invalidationChannel = \"cache-invalidations\";\r\nvar cache = new CompositeCache(\r\n    new RedisInvalidationReceiver(\r\n        new MemoryCache(/* arguments */),\r\n        subscriber,\r\n        invalidationChannel\r\n    ),\r\n    new CompositeCache(\r\n        new RedisCache(/* arguments */),\r\n        new RedisInvalidationSender(subscriber, invalidationChannel)\r\n    )\r\n);\r\n```\r\n\r\nTake in account that when a `calculateValue` function returns a `null` value nothing is cached and a `null` value is returned back to the caller.\r\n\r\n# Details\r\n\r\n- [API Documentation](doc/api-documentation.md)\r\n\r\n- [Using with Asp.Net-Core](doc/dotnet-core.md)\r\n\r\n- [Architecture](doc/architecture.md)\r\n\r\n- [Requirements and best practices](doc/best-practices.md)\r\n\r\n# Upgrading from a previous version\r\n\r\nThis package follows [semantic versioning](https://semver.org/), which means that upgrading to a higher MINOR or PATCH version should always work. Upgrading to a higher MAJOR version will require code changes. Make sure to read the release notes before upgrading.\r\n\r\n# Contributing\r\n\r\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\r\n\r\n# License\r\n\r\nThis code is released under the MIT license. Please refer to [LICENSE.md](LICENSE.md) for details.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintelligenthack%2Fintelligentcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintelligenthack%2Fintelligentcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintelligenthack%2Fintelligentcache/lists"}