-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from TomPallister/feature/clear-cache
Feature/clear cache
- Loading branch information
Showing
22 changed files
with
397 additions
and
34 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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Ocelot.Cache | ||
{ | ||
public interface IOcelotCache<T> | ||
{ | ||
void Add(string key, T value, TimeSpan ttl); | ||
void AddAndDelete(string key, T value, TimeSpan ttl); | ||
T Get(string key); | ||
void Add(string key, T value, TimeSpan ttl, string region); | ||
void AddAndDelete(string key, T value, TimeSpan ttl, string region); | ||
T Get(string key, string region); | ||
void ClearRegion(string region); | ||
} | ||
} |
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,9 @@ | ||
using Ocelot.Configuration.File; | ||
|
||
namespace Ocelot.Cache | ||
{ | ||
public interface IRegionCreator | ||
{ | ||
string Create(FileReRoute reRoute); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Linq; | ||
using Ocelot.Configuration; | ||
using Ocelot.Configuration.File; | ||
|
||
namespace Ocelot.Cache | ||
{ | ||
|
||
public class RegionCreator : IRegionCreator | ||
{ | ||
public string Create(FileReRoute reRoute) | ||
{ | ||
if(!string.IsNullOrEmpty(reRoute?.FileCacheOptions?.Region)) | ||
{ | ||
return reRoute?.FileCacheOptions?.Region; | ||
} | ||
|
||
var methods = string.Join("", reRoute.UpstreamHttpMethod.Select(m => m)); | ||
|
||
var region = $"{methods}{reRoute.UpstreamPathTemplate.Replace("/", "")}"; | ||
|
||
return region; | ||
} | ||
} | ||
} |
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,13 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Ocelot.Cache | ||
{ | ||
public class Regions | ||
{ | ||
public Regions(List<string> value) | ||
{ | ||
Value = value; | ||
} | ||
public List<string> Value {get;private set;} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
public class FileCacheOptions | ||
{ | ||
public int TtlSeconds { get; set; } | ||
public string Region {get; set;} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Ocelot.Cache; | ||
using Ocelot.Configuration.Provider; | ||
|
||
namespace Ocelot.Controllers | ||
{ | ||
[Authorize] | ||
[Route("outputcache")] | ||
public class OutputCacheController : Controller | ||
{ | ||
private IOcelotCache<HttpResponseMessage> _cache; | ||
|
||
public OutputCacheController(IOcelotCache<HttpResponseMessage> cache) | ||
{ | ||
_cache = cache; | ||
} | ||
|
||
[HttpDelete] | ||
[Route("{region}")] | ||
public IActionResult Delete(string region) | ||
{ | ||
_cache.ClearRegion(region); | ||
return new NoContentResult(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.