Skip to content

A high-performance, generic, and thread-safe caching library for C# applications, designed to boost performance by storing frequently accessed data in memory. Supporting any key-value type combination, it reduces redundant data fetching from slow sources like databases or APIs, using the Decorator and Chain

Notifications You must be signed in to change notification settings

marwanfarook22/Custom-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Custom Cache - C# Caching Library πŸš€

A high-performance, generic caching library for C# applications, providing in-memory caching for any data type with any key type. This library significantly boosts application performance by reducing redundant data fetching operations. ⚑

Table of Contents

Overview πŸ“‹

Custom Cache is a lightweight, thread-safe caching library designed to store frequently accessed data in memory, minimizing costly operations like database queries, API calls, or file system access. It supports generic types for keys and values, making it highly flexible and type-safe.

Problem Statement 🐌

Applications often face performance bottlenecks when repeatedly fetching the same data from slow sources (e.g., databases, APIs, file systems). For instance, a DownloadData method taking 1 second per call can lead to significant delays and resource waste when called multiple times for the same data.

Solution πŸ’‘

The Custom Cache library addresses this by:

  • πŸ’Ύ Storing data in memory for quick access
  • πŸ”§ Supporting any key-value type combination
  • ⚑ Reducing data access time for cached items
  • πŸ›‘οΈ Ensuring thread safety for concurrent operations

Key Features ✨

  • Generic Type Support: Works with any key type (e.g., string, int, Guid, custom objects) and any data type (e.g., primitives, objects, collections). βœ…
  • Performance Optimization:
    • First access: Fetches from the source (normal speed). 🐌
    • Subsequent access: Near-instantaneous retrieval from cache. 🏎️
  • Thread Safety: Safe for multi-threaded applications with concurrent read/write support. πŸ”’
  • Easy Integration: Intuitive API with minimal setup. πŸ”„
  • Design Patterns:
    • 🎯 Decorator Pattern: Enhances data access with caching.
    • πŸ”— Chain of Responsibility: Handles cache misses gracefully.
    • πŸ“¦ Dictionary: Uses Dictionary<TKey, TValue> for high-performance storage.

installation πŸš€

Clone the repository:

git clone https://github.com/username/custom-cache.git

Usage Example πŸ’»

Below is an example of how to use the Custom Cache library:

using CustomCache;
// Simulated slow data source
private UserData DownloadUserData(string userId)
{
    Thread.Sleep(1000); // Simulate 1-second delay
    return new UserData { Id = userId, Name = "John Doe" };
}
// Usage
var cache = new Cache<string, UserData>();
// First access: Fetches from source (slow)
var userData1 = cache.Get("user123", () => DownloadUserData("user123"));
Console.WriteLine(userData1.Name); // Output: John Doe
// Second access: Served from cache (fast)
var userData2 = cache.Get("user123", () => DownloadUserData("user123"));
Console.WriteLine(userData2.Name); // 
Output: John Doe (instantaneous)

Optional Performance Chart To highlight the performance benefits, here’s a sample chart comparing cached vs. non-cached access times: chart

Support πŸ“§ For questions or support, please: Open an issue on GitHub. Contact us via marwanfarook99@gmail.com

About

A high-performance, generic, and thread-safe caching library for C# applications, designed to boost performance by storing frequently accessed data in memory. Supporting any key-value type combination, it reduces redundant data fetching from slow sources like databases or APIs, using the Decorator and Chain

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages