https://github.com/dotnet-labs/memorycachelabs
Cache in-memory in ASP.NET Core | tests | immutable
https://github.com/dotnet-labs/memorycachelabs
cache dotnet dotnet-core dotnetcore immutable memory-cache unit-testing unitest
Last synced: 20 days ago
JSON representation
Cache in-memory in ASP.NET Core | tests | immutable
- Host: GitHub
- URL: https://github.com/dotnet-labs/memorycachelabs
- Owner: dotnet-labs
- License: mit
- Created: 2021-01-26T15:14:41.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-12T17:48:21.000Z (about 5 years ago)
- Last Synced: 2025-05-21T12:51:30.617Z (12 months ago)
- Topics: cache, dotnet, dotnet-core, dotnetcore, immutable, memory-cache, unit-testing, unitest
- Language: C#
- Homepage:
- Size: 111 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Memory Cache Lab
## [Medium Article: IMemoryCache: Immutable Collections and Unit Tests](https://codeburst.io/imemorycache-immutable-collections-and-unit-tests-cfac7b389a5)
There are many introductory articles talking about using the `IMemoryCache` to store data in the memory of the webserver. However, few of them have mentioned how to ensure the consistency of cached values at runtime. In other words, if not designed carefully, the cached values could be mutated accidentally in code.
In this article, I will first present an example cache service that allows us to mutate a cached entry, which is an undesired outcome in most cases. To improve the implementation, next, I will show you a way to create immutable collections as cache objects by using `IReadOnlyList` and `record`.

## License
Feel free to use the code in this repository as it is under MIT license.