{"id":18798581,"url":"https://github.com/liteobject/demo.memorycache","last_synced_at":"2026-01-02T02:30:15.956Z","repository":{"id":90788596,"uuid":"365578216","full_name":"LiteObject/Demo.MemoryCache","owner":"LiteObject","description":"Demo of how to cache JWT (based on expiration) using .NET MemoryCache","archived":false,"fork":false,"pushed_at":"2024-09-05T02:31:10.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T18:21:15.365Z","etag":null,"topics":["csharp","jwt-token"],"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/LiteObject.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":"2021-05-08T17:53:14.000Z","updated_at":"2024-09-05T02:31:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"3fe77f96-d3d6-4560-841d-033e2575486f","html_url":"https://github.com/LiteObject/Demo.MemoryCache","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/LiteObject%2FDemo.MemoryCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiteObject%2FDemo.MemoryCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiteObject%2FDemo.MemoryCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiteObject%2FDemo.MemoryCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LiteObject","download_url":"https://codeload.github.com/LiteObject/Demo.MemoryCache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239727055,"owners_count":19687099,"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":["csharp","jwt-token"],"created_at":"2024-11-07T22:12:24.735Z","updated_at":"2026-01-02T02:30:15.692Z","avatar_url":"https://github.com/LiteObject.png","language":"C#","readme":"# Enhance Performance with MemoryCache in C#\n\n\n## Introduction:\nIn modern software development, optimizing performance is crucial for delivering efficient and responsive applications. Caching is a powerful technique that can significantly improve performance by storing frequently accessed data in memory. In this article, we will explore the MemoryCache class in C# and see how it can be used to enhance performance in your applications.\n\n## What is MemoryCache?\nMemoryCache is a caching mechanism provided by the .NET framework that allows you to store data in memory for quick access. It provides an in-memory key-value store that can be used to cache frequently accessed data, such as database query results, API responses, or expensive computation results. The MemoryCache class provides methods for adding, retrieving, and removing items from the cache.\n\n## Example Usage:\nLet's look at a simple example to understand how MemoryCache works in practice:\n\n```csharp\nusing System;\nusing System.Runtime.Caching;\n\nclass Program\n{\n    static void Main()\n    {\n        // Create a new MemoryCache instance\n        MemoryCache cache = MemoryCache.Default;\n\n        // Add an item to the cache\n        cache.Add(\"myKey\", \"myValue\", DateTimeOffset.Now.AddMinutes(10));\n\n        // Retrieve the item from the cache\n        string value = cache.Get(\"myKey\") as string;\n        Console.WriteLine(value);\n\n        // Remove the item from the cache\n        cache.Remove(\"myKey\");\n\n        // Check if the item exists in the cache\n        bool exists = cache.Contains(\"myKey\");\n        Console.WriteLine(exists);\n    }\n}\n\n```\n\nIn this example, we first create a new instance of the MemoryCache class using the `MemoryCache.Default` property. We then add an item to the cache using the `Add` method, specifying a key, value, and expiration time. In this case, the item will be valid for 10 minutes.\n\nTo retrieve the item from the cache, we use the `Get` method, which returns the value associated with the specified key. We can cast the retrieved value to the appropriate type.\n\nTo remove an item from the cache, we use the `Remove` method, passing the key as the argument. We can also check if an item exists in the cache using the `Contains` method, which returns a boolean indicating whether the key is present.\n\n## Conclusion:\nMemoryCache is a valuable tool for enhancing performance in your C# applications. By caching frequently accessed data in memory, you can reduce the need for expensive computations or frequent database queries, resulting in improved response times and a smoother user experience. The MemoryCache class provides a simple and efficient way to implement caching in your applications. Remember to use appropriate cache expiration times and consider cache invalidation strategies to ensure your cached data remains up-to-date.\n\n---\n\n## About the demo app:\nA demo to show how to set expiration in .NET MemoryCache object matching JWT exp\n\n---","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliteobject%2Fdemo.memorycache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliteobject%2Fdemo.memorycache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliteobject%2Fdemo.memorycache/lists"}