Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement abstract cache buster: ICacheBuster #51
- Loading branch information
Showing
19 changed files
with
256 additions
and
44 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
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace Smidge.Cache | ||
{ | ||
/// <summary> | ||
/// Creates a cache bust value for the lifetime of the app domain | ||
/// </summary> | ||
/// <remarks> | ||
/// Essentially means that all caches will be busted when the app restarts | ||
/// </remarks> | ||
public class AppDomainLifetimeCacheBuster : ICacheBuster | ||
{ | ||
public AppDomainLifetimeCacheBuster() | ||
{ | ||
_value = new Lazy<string>(() => DateTime.UtcNow.Ticks.ToString(NumberFormatInfo.InvariantInfo)); | ||
} | ||
|
||
private static Lazy<string> _value; | ||
|
||
public string GetValue() | ||
{ | ||
return _value.Value; | ||
} | ||
} | ||
} |
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; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Smidge.Cache | ||
{ | ||
/// <summary> | ||
/// Used to resolve an instance of ICacheBuster from the registered ones in the container | ||
/// </summary> | ||
public sealed class CacheBusterResolver | ||
{ | ||
private readonly IEnumerable<ICacheBuster> _cacheBusters; | ||
|
||
public CacheBusterResolver(IEnumerable<ICacheBuster> cacheBusters) | ||
{ | ||
_cacheBusters = cacheBusters; | ||
} | ||
|
||
/// <summary> | ||
/// Get the cache buster for the given type | ||
/// </summary> | ||
/// <param name="busterType"></param> | ||
/// <returns></returns> | ||
public ICacheBuster GetCacheBuster(Type busterType) | ||
{ | ||
return _cacheBusters.FirstOrDefault(x => x.GetType() == busterType); | ||
} | ||
} | ||
} |
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 System; | ||
using System.Collections; | ||
|
||
namespace Smidge.Cache | ||
{ | ||
/// <summary> | ||
/// Based on a static string specified in config | ||
/// </summary> | ||
public class ConfigCacheBuster : ICacheBuster | ||
{ | ||
private readonly ISmidgeConfig _config; | ||
|
||
public ConfigCacheBuster(ISmidgeConfig config) | ||
{ | ||
if (config == null) throw new ArgumentNullException(nameof(config)); | ||
_config = config; | ||
} | ||
public string GetValue() | ||
{ | ||
return _config.Version; | ||
} | ||
} | ||
} |
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,14 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Smidge.Cache | ||
{ | ||
/// <summary> | ||
/// Returns the value to cache bust the request | ||
/// </summary> | ||
public interface ICacheBuster | ||
{ | ||
string GetValue(); | ||
} | ||
} |
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
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.