Skip to content

Commit

Permalink
some minor changes in cache endpoint.
Browse files Browse the repository at this point in the history
use nuget package instead of direct project reference.
update to .NET 7.0.
  • Loading branch information
omid-ahmadpour committed Sep 22, 2023
1 parent 67a6fb5 commit de6d9c3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
9 changes: 3 additions & 6 deletions Sample/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ public class WeatherForecastController : ControllerBase
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;
private readonly IWeatherService weatherService;

public WeatherForecastController(ILogger<WeatherForecastController> logger,
IWeatherService weatherService)
public WeatherForecastController(IWeatherService weatherService)
{
_logger = logger;
this.weatherService = weatherService ?? throw new ArgumentNullException(nameof(weatherService));
}

Expand All @@ -41,9 +38,9 @@ public IEnumerable<WeatherForecast> Get()
}

[HttpGet("cache")]
public async Task<IEnumerable<WeatherForecast>> GetFromCache()
public async Task<IEnumerable<WeatherForecast>> GetFromCache(string cityName)
{
var result = await weatherService.GetWeatherAsync();
var result = await weatherService.GetWeatherAsync(cityName);
return result;
}
}
Expand Down
12 changes: 5 additions & 7 deletions Sample/Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<UserSecretsId>6b60c148-640f-49ca-86d2-38fdef0dc635</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\PolyCache\PolyCache\PolyCache.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.11" />
<PackageReference Include="PolyCache" Version="1.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Sample/Services/IWeatherService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Sample.Services
{
public interface IWeatherService
{
Task<IEnumerable<WeatherForecast>> GetWeatherAsync();
Task<IEnumerable<WeatherForecast>> GetWeatherAsync(string cityName);
}
}
4 changes: 2 additions & 2 deletions Sample/Services/WeatherService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public WeatherService(IStaticCacheManager staticCacheManager)
this.staticCacheManager = staticCacheManager ?? throw new ArgumentNullException(nameof(staticCacheManager));
}

public async Task<IEnumerable<WeatherForecast>> GetWeatherAsync()
public async Task<IEnumerable<WeatherForecast>> GetWeatherAsync(string cityName)
{
var result = await staticCacheManager.GetWithExpireTimeAsync(
new CacheKey(CachePrefix),
new CacheKey(CachePrefix + cityName),
CacheExpiryTime,
async () => await GetWeather());

Expand Down

0 comments on commit de6d9c3

Please sign in to comment.