Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
asliyigiit authored Dec 13, 2023
1 parent 42a2693 commit 2fc0b9f
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
# Table Of Content
1. [Features](#features)
2. [Get It Started](#get-it-started)
3. [Contributions](#contributions)
4. [License](#license)
3. [Cache Attribute Example](#cache-example)
4. [Contributions](#contributions)
5. [License](#license)

# Features
1. <b>Aspect-Oriented Programming (AOP):</b> <br />
Expand Down Expand Up @@ -84,7 +85,47 @@ public class CustomAspectAttribute : NexusAopAttribute
4. <b>Build and Run: </b><br />

Build your project, and NexusAop will seamlessly weave the specified aspects into your methods during runtime.

# Cache Attribute Example
```csharp
public class CacheMethodAttribute : NexusAopAttribute
{
public CacheMethodAttribute(
int ttlAsSecond)
{
Ttl = TimeSpan.FromSeconds(ttlAsSecond);
}

public CacheMethodAttribute()
{
Ttl = null;
}

public TimeSpan? Ttl { get; set; }

public override async Task ExecuteAsync(NexusAopContext context)
{
if (!CheckMethodCacheable(context.TargetMethod))
{
return;
}
var cacheKey = GetCacheKey(context.TargetMethod, context.TargetMethodsArgs);
var result = GetResult(cacheKey);

if (result != null)
{
context.Result= result;
return;
}

result = await context.SetResultAsync();
await SetCacheAsync(context.TargetMethod, context.TargetMethodsArgs,result);
}

// ...
// see CacheMethodAttribute.cs in /Samples/Cache for other logics
// ...
}
```
# Contributions
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please feel free to create an issue or submit a pull request.

Expand Down

0 comments on commit 2fc0b9f

Please sign in to comment.