Why SmartCache.NET?
✅ Thread-safe execution using ConcurrentDictionary and lock control.
✅ Supports both synchronous and asynchronous execution patterns.
✅ TTL-based (time-to-live) expiration and optional async refresh.
✅ No third-party dependencies — pure .NET.
✅ Ideal for high-load financial or API systems.
How It Works
To use SmartCache.NET, simply wrap your expensive code block with:
var result = await Executor.Instance.GetDataAsync(() => {
return ExpensiveOperation();
}, paramValues, 30, 10); // Cache for 30 secs, refresh after 10
Under the hood, SmartCache.NET:
Generates a unique cache key based on the method and parameters:
- Checks if data exists in cache — if yes, returns instantly
- If about to expire, returns cached data and triggers async refresh
- Ensures only one thread populates cache when expired
Performance Example
The included Program.cs demo simulates 10 parallel requests. Despite concurrency, the executor ensures only one actual execution happens:
- ---- Starting parallel calls ----
- [CodeBlock] Executed by Thread: 5
- [Total CodeBlock Executions]: 1
- [Total Time]: 510 ms
Installation
You can install the NuGet package (coming soon) or clone the repo:
git clone https://github.com/MuhammadOmerKhan/SmartCache.NET.git
Use Cases
- 📈 Financial dashboards and stock APIs
- 🧠 AI & ML inference pipelines
- 🌐 Web APIs with heavy computational payload
- 📊 BI reporting engines
Contribute
We welcome contributions, feedback, and stars ⭐ on GitHub!
Visit GitHub Repository →
License
SmartCache.NET is released under the MIT License.







