-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f1d68b
commit 9ccc66a
Showing
7 changed files
with
130 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using CacheDrive.Services; | ||
|
||
namespace CacheDrive.ExampleConsoleApp; | ||
|
||
public class App(ICacheService cacheService) | ||
{ | ||
public async Task Run() | ||
{ | ||
string cacheKey = "testKey"; | ||
|
||
await cacheService.SetAsync(cacheKey, "test text..."); | ||
|
||
Console.WriteLine(cacheService.TryGetValue(cacheKey, out string cachedValue) | ||
? $"OK: cached value - {cachedValue}" | ||
: $"NOK: cached value - {cachedValue}"); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
CacheDrive.ExampleConsoleApp/CacheDrive.ExampleConsoleApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\CacheDrive\CacheDrive.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="appsettings.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using CacheDrive.ExampleConsoleApp; | ||
using CacheDrive.Extensions; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
var services = new ServiceCollection(); | ||
|
||
IConfiguration configuration = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | ||
.AddEnvironmentVariables() | ||
.Build(); | ||
|
||
services.RegisterCacheDrive(configuration, configurationSectionName: "CacheSettings"); | ||
|
||
services.AddTransient<App>(); | ||
|
||
// create service provider | ||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
await serviceProvider.GetService<App>()!.Run(); | ||
|
||
serviceProvider.Dispose(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"CacheSettings": { | ||
"CacheEnabled": true, | ||
"CacheFolderName": "cache", | ||
"CacheExpirationType": "Minutes", | ||
"CacheExpiration": 60, | ||
"CacheType": "MemoryAndFile", | ||
"InitializeOnStartup": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters