{"id":26673754,"url":"https://github.com/mjebrahimi/smartcachemanager","last_synced_at":"2025-07-23T11:37:58.459Z","repository":{"id":54193708,"uuid":"279348600","full_name":"mjebrahimi/SmartCacheManager","owner":"mjebrahimi","description":"SmartCacheManager is a smart caching module to cache objects with resilient and variable expiration timing that is useful for caching result of web services.","archived":false,"fork":false,"pushed_at":"2024-01-13T10:04:35.000Z","size":794,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T06:14:05.791Z","etag":null,"topics":["cache","caching","flights-api","iata","iata-codes"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mjebrahimi.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":"2020-07-13T15:58:39.000Z","updated_at":"2024-07-30T23:36:09.000Z","dependencies_parsed_at":"2022-08-13T08:50:49.150Z","dependency_job_id":null,"html_url":"https://github.com/mjebrahimi/SmartCacheManager","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjebrahimi%2FSmartCacheManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjebrahimi%2FSmartCacheManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjebrahimi%2FSmartCacheManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjebrahimi%2FSmartCacheManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mjebrahimi","download_url":"https://codeload.github.com/mjebrahimi/SmartCacheManager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525138,"owners_count":21118619,"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","caching","flights-api","iata","iata-codes"],"created_at":"2025-03-26T01:37:36.372Z","updated_at":"2025-04-12T06:14:09.279Z","avatar_url":"https://github.com/mjebrahimi.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NuGet](https://img.shields.io/nuget/v/SmartCacheManager.svg)](https://www.nuget.org/packages/SmartCacheManager)\n[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)\n[![Build Status](https://github.com/mjebrahimi/SmartCacheManager/workflows/.NET%20Core/badge.svg)](https://github.com/mjebrahimi/SmartCacheManager)\n\n# SmartCacheManager\n**SmartCacheManager** is a response caching module which cache objects with resilient and variable expiration time that is useful for caching the result of web services and other calculations.\n\n## Features\n- • Caching objects using [EasyCaching](https://github.com/dotnetcore/EasyCaching) \n    - Supports various caching providers such as **In-Memory**, **Redis**, **Memcached**, **Disk**, **Sqlite**, ...\n- • Serializing data\n    - Supports various caching serializers such as **BinaryFormatter**, **MessagePack**, **Json**, **Protobuf**, ...\n- • Settings for cache expiration time by specifying the **minimum** and **maximum** duration\n- • Increasing and decreasing cache expiration time automatically based on the date of search and RPM\n- • Calculates the **RPM (request per minute)** of a search\n- • Ability to **limit** searches based on maximum limit count in a specified time range\n- • Ability to configuring cache-key dynamically based on your needs\n- • **Async** support with cancellation tokens\n- • **Thread-safety** support\n- • Flexible, lightweight and **highly customizable**\n- • Logs **Sensitive Data** using [Serilog](https://github.com/serilog/serilog)\n    - Logs all errors occures in services\n    - Logs all steps of the search and caching process\n    - Logs all incomming requests to this module\n    - Logs all outgoing request from this module to external services\n    - Logs the execution time of service methods using [MethodTimer.Fody](https://github.com/Fody/MethodTimer)\n    - Logs to the **Sql-Server** (by default) and supports **Console**, **Debug**, **File**, **EventViwer**, **Seq**, **ElasticSearch** and ...\n\n\n## Getting Started\n\n### 1. Install Package\n\n\u003e For the .NET Core 2.2 use [v1.0.0](https://www.nuget.org/packages/SmartCacheManager/1.0.0) and for the .NET Core 3.1 use [v2.0.0](https://www.nuget.org/packages/SmartCacheManager/2.0.0) of SmartCacheManager:\n```\nPM\u003e Install-Package SmartCacheManager\n```\n\n### 2. Implement your own cache-manager service\n\nFor example: A simple implementation of a FlightCacheManager could be like this:\n\n```csharp\npublic class FlightCacheManager : SmartCacheManager\u003cFlightSearchModel\u003e, IFlightCacheManager\n{\n    public FlightCacheManager(ICacheManager cacheManager, ILoggerFactory loggerFactory, ISystemClock systemClock,\n        ICacheSettingService\u003cCacheSetting\u003e cacheSettingService, ISearchHistoryService\u003cCacheSetting, LimitSetting\u003e searchHistoryService)\n        : base(cacheManager, loggerFactory, systemClock, cacheSettingService, searchHistoryService)\n    {\n    }\n    \n    protected override string GenerateSearchHistoryKey(FlightSearchModel searchModel)\n    {\n        return GenerateSearchResultKey(searchModel);\n    }\n    \n    protected override string GenerateSearchResultKey(FlightSearchModel searchModel)\n    {\n        return $\"{searchModel.Origin}-{searchModel.Destination}-{searchModel.SearchDate.ToString(\"yyyy-MM-dd\")}\";\n    }\n    \n    protected override DateTime GetSearchDate(FlightSearchModel searchModel)\n    {\n        return searchModel.SearchDate;\n    }\n}\n\npublic class FlightSearchModel\n{\n    public string Origin { get; set; }\n    public string Destination { get; set; }\n    public DateTime SearchDate { get; set; }\n}\n```\n\n### 3. Register services\n\nRegister SmartCacheManager in your DI container by calling `services.AddSmartCacheManager()` and also, register your own cache-manager implementation:\n\n```csharp\npublic static void ConfigureServices(IServiceCollection services)\n{\n    services.AddSmartCacheManager(opt =\u003e opt.UseSqlServer(\"Data Source=.;Initial Catalog=CacheManageDb;Integrated Security=true\");\n    services.AddScoped\u003cFlightCacheManager\u003e();\n    //...\n}\n```\n\n### 4. Initialize it\n\nInitialize SmartCacheManager using `app.InitialSmartCacheManager()` in the `Configure` method of `Startup.cs`:\n\n```csharp\npublic static void Configure(IApplicationBuilder app, IWebHostEnvironment env)\n{\n    app.InitialSmartCacheManager();\n    //...\n```\n\n### 5. Use it\n\nInject your own implementation of cache-manager to your services and use it by calling `SearchFromCacheAsync()` method:\n\n```csharp\nvar supplier = FlightSupplierts.Amadeus; // Supplier could be any type: string, enum or ...\nvar searchModel = new FlightSearchModel\n{\n    Origin = \"AMS\",\n    Destination = \"HAM\",\n    SearchDate = DateTime.Now.AddDays(10)\n};\n\nvar result = await _flightCacheManager.SearchFromCacheAsync(searchModel, supplier, () =\u003e\n{\n    return _amadeusFlightService.SearchAsync(searchModel);\n});\n```\n\n## Contributing\n\nCreate an [issue]() if you find a bug or have a suggestion or question. If you want to develop this project:\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request\n\n## Give a Star! ⭐️\n\nIf you find this repository useful, please give it a star. Thanks!\n\n## License/Copyright \n\nSmartCacheManager is Copyright © 2020 [Mohammd Javad Ebrahimi](https://github.com/mjebrahimi) under the [GNU GPLv3 License](/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjebrahimi%2Fsmartcachemanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmjebrahimi%2Fsmartcachemanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjebrahimi%2Fsmartcachemanager/lists"}