{"id":19283045,"url":"https://github.com/vikashchauhan51/datacache","last_synced_at":"2026-02-17T18:35:04.105Z","repository":{"id":116103483,"uuid":"131477547","full_name":"VikashChauhan51/DataCache","owner":"VikashChauhan51","description":"DataCache is a flexible, high-performance caching library designed for both in-memory and Redis-based caching scenarios. It supports various eviction strategies, including LRU (Least Recently Used), LFU (Least Frequently Used), and MRU (Most Recently Used), to handle cache eviction efficiently. ","archived":false,"fork":false,"pushed_at":"2025-03-07T14:41:28.000Z","size":71,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T01:38:52.793Z","etag":null,"topics":["cache-storage","csharp","memory-cache"],"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/VikashChauhan51.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,"zenodo":null}},"created_at":"2018-04-29T08:19:28.000Z","updated_at":"2025-03-07T14:41:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"9abf7889-44ca-4d56-9340-ab0ea48c354c","html_url":"https://github.com/VikashChauhan51/DataCache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/VikashChauhan51/DataCache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VikashChauhan51%2FDataCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VikashChauhan51%2FDataCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VikashChauhan51%2FDataCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VikashChauhan51%2FDataCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VikashChauhan51","download_url":"https://codeload.github.com/VikashChauhan51/DataCache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VikashChauhan51%2FDataCache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29552798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T18:16:07.221Z","status":"ssl_error","status_checked_at":"2026-02-17T18:16:04.782Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-storage","csharp","memory-cache"],"created_at":"2024-11-09T21:29:32.114Z","updated_at":"2026-02-17T18:34:59.095Z","avatar_url":"https://github.com/VikashChauhan51.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# DataCache\n\nDataCache is a flexible, high-performance caching library designed for both in-memory and Redis-based caching scenarios. It supports various eviction strategies, including LRU (Least Recently Used), LFU (Least Frequently Used), and MRU (Most Recently Used), to handle cache eviction efficiently. The library also allows for configurable memory size limits, Time-To-Live (TTL) management, and provides a seamless integration between Redis and in-memory caching for optimized performance.\n\n## Features\n\n- **Eviction Strategies**: Supports multiple eviction strategies such as LRU, LFU, MRU, and more.\n- **Memory Size Limit**: Configurable memory size limits for in-memory caches.\n- **TTL (Time-To-Live) Management**: Auto-removal of expired items based on TTL settings.\n- **Redis Integration**: Provides a Redis-based caching option with support for database selection and optimization through an optional in-memory cache.\n- **Thread-Safe Operations**: Ensures thread safety for concurrent cache access.\n- **Modular Design**: Extensible design allowing custom cache implementations and eviction strategies.\n\n## Installation\n\n1. Clone the repository:\n    ```bash\n    git clone https://github.com/VikashChauhan51/DataCache.git\n    cd DataCache\n    ```\n\n2. Add a reference to the project or use NuGet to install the package:\n    ```bash\n    dotnet add package DataCache --version x.y.z\n    ```\n\n## Usage\n\n### 1. Basic In-Memory Cache Example\n\n```csharp\nvar cacheOptions = new CacheOptions\n{\n    MaxMemorySize = 1048576, // 1 MB\n    EvictionType = Eviction.LRU,\n    TtlInterval = TimeSpan.FromMinutes(5)\n};\n\nvar memoryCache = new MemoryCache(cacheOptions);\n\n// Add an item\nmemoryCache.Put(\"item1\", new CacheItem(\"Value1\", DateTimeOffset.Now, TimeSpan.FromMinutes(10)));\n\n// Get an item\nvar item = memoryCache.Get(\"item1\");\n\n// Check item expiration\nif (item?.IsExpired ?? false)\n{\n    memoryCache.Delete(\"item1\");\n}\n```\n\n### 2. Redis Cache Example with Optimized In-Memory Caching\n\n```csharp\nvar redisCacheOptions = new RedisCacheOptions(\n    maxMemorySize: 2097152,  // 2 MB\n    evictionType: Eviction.LFU,\n    TtlInterval: TimeSpan.FromMinutes(10),\n    databaseIndex: 0,\n    optimized: true\n);\n\nvar redisConnection = ConnectionMultiplexer.Connect(\"localhost\");\nvar redisCache = new RedisCache(redisCacheOptions, redisConnection);\n\n// Add an item\nawait redisCache.PutAsync(\"user:1\", new CacheItem(\"User Data\", DateTimeOffset.Now, TimeSpan.FromMinutes(30)));\n\n// Get an item\nvar userData = await redisCache.GetAsync(\"user:1\");\n```\n\n### 3. Custom Eviction Strategy\n\nTo implement your own eviction strategy, you can extend the `IEvictionStrategy` interface and plug it into the cache configuration.\n\n```csharp\npublic class CustomEvictionStrategy\u003cTKey\u003e : IEvictionStrategy\u003cTKey\u003e\n{\n    public void RecordAccess(TKey key) { /* Custom logic */ }\n    public void RecordInsertion(TKey key) { /* Custom logic */ }\n    public TKey? Evict() { /* Custom eviction logic */ }\n}\n\n// Usage\nvar cacheOptions = new CacheOptions\n{\n    MaxMemorySize = 1048576, // 1 MB\n    EvictionType = Eviction.None, // Use your custom strategy\n};\n\nvar customEvictionStrategy = new CustomEvictionStrategy\u003cstring\u003e();\nvar memoryCache = new MemoryCache(cacheOptions, customEvictionStrategy);\n```\n\n## Configuration\n\nThe cache options allow full customization based on your needs:\n\n- **MaxMemorySize**: Limits the memory size used for in-memory caching.\n- **EvictionType**: Specify which eviction strategy to use. Choose from `Eviction.LRU`, `Eviction.LFU`, `Eviction.MRU`, and others.\n- **TtlInterval**: Interval for TTL checks to clean up expired items.\n- **Redis Options**:\n  - **DatabaseIndex**: Specify which Redis database to use.\n  - **Optimized**: Enable/disable in-memory caching for performance optimization.\n\n## Contributing\n\nWe welcome contributions! Please feel free to open issues, submit PRs, and suggest new features. Make sure to write unit tests for your contributions using xUnit, FluentAssertions, and FakeItEasy.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n---\n\nThis template covers the basics of explaining your library, how to use it, and how to contribute. You can modify this as necessary based on your project's specific needs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvikashchauhan51%2Fdatacache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvikashchauhan51%2Fdatacache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvikashchauhan51%2Fdatacache/lists"}