Skip to content

Commit

Permalink
remoção da classe CacheType e ajustes no projeto
Browse files Browse the repository at this point in the history
  • Loading branch information
Luciano Lima committed Jul 11, 2018
1 parent 7055c1e commit 20fda9f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 37 deletions.
12 changes: 6 additions & 6 deletions source/Otc.Cache/CacheDistributed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ namespace Otc.Cache
{
public class CacheDistributed : ICache
{
private readonly IDistributedCache _distrinutedCache;
private readonly IDistributedCache _distributedCache;
private readonly ILogger _logger;
public const int CacheErrorEventId = 23332;
public CacheDistributed(IDistributedCache distrinutedCache, ILoggerFactory loggerFactory)
public CacheDistributed(IDistributedCache distributedCache, ILoggerFactory loggerFactory)
{
if (loggerFactory == null)
{
throw new ArgumentNullException(nameof(loggerFactory));
}

_distrinutedCache = distrinutedCache;
_distributedCache = distributedCache;
_logger = loggerFactory.CreateLogger<CacheDistributed>();
}

public void Remove(string key)
{
_distrinutedCache.Remove(key);
_distributedCache.Remove(key);
}

public void Set<T>(string key, T entity, int minutes)
Expand All @@ -39,7 +39,7 @@ public void Set<T>(string key, T entity, int minutes)

try
{
_distrinutedCache.SetString(key, value, options);
_distributedCache.SetString(key, value, options);
}
catch (Exception e)
{
Expand All @@ -54,7 +54,7 @@ public bool TryGetValue<T>(string key, out T entity)

try
{
value = _distrinutedCache.GetString(key);
value = _distributedCache.GetString(key);
}
catch (Exception e)
{
Expand Down
10 changes: 1 addition & 9 deletions source/Otc.Cache/CacheParametros.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,11 @@ public class CacheParametros

public string Aplicacao { get; private set; }

public CacheType CacheType { get; private set; }

public CacheParametros(int time, bool enabled, string aplicacao, CacheType cacheType)
public CacheParametros(int time, bool enabled, string aplicacao)
{
Time = time;
Enabled = enabled;
Aplicacao = aplicacao;
CacheType = cacheType;
}

public void SetEnabled(bool enabled)
{
Enabled = enabled;
}
}
}
8 changes: 0 additions & 8 deletions source/Otc.Cache/CacheType.cs

This file was deleted.

2 changes: 0 additions & 2 deletions source/Otc.Cache/ICacheConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
{
public interface ICacheConfiguration
{
CacheType CacheType { get; }

int CacheDuration { get; set; }

bool Enabled { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions source/Otc.Cache/Otc.Cache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>

Expand Down
6 changes: 3 additions & 3 deletions source/Otc.Cache/OtcCacheServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Configure(ICacheConfiguration applicationConfiguration)
throw new ArgumentNullException(nameof(applicationConfiguration));
}

if (applicationConfiguration.CacheType == CacheType.Redis)
if (applicationConfiguration.GetType() == typeof(RedisCacheConfiguration))
{
RedisCacheConfiguration config = applicationConfiguration as RedisCacheConfiguration;

Expand All @@ -51,7 +51,7 @@ public void Configure(ICacheConfiguration applicationConfiguration)
options.Configuration = config.RedisConnection;
});
}
else if (applicationConfiguration.CacheType == CacheType.Sql)
else if (applicationConfiguration.GetType() == typeof(SqlCacheConfiguration))
{
SqlCacheConfiguration config = applicationConfiguration as SqlCacheConfiguration;

Expand All @@ -63,7 +63,7 @@ public void Configure(ICacheConfiguration applicationConfiguration)
});
}

services.AddSingleton(c => new CacheParametros(applicationConfiguration.CacheDuration, applicationConfiguration.Enabled, applicationConfiguration.Aplicacao, applicationConfiguration.CacheType));
services.AddSingleton(c => new CacheParametros(applicationConfiguration.CacheDuration, applicationConfiguration.Enabled, applicationConfiguration.Aplicacao));
services.AddSingleton(applicationConfiguration);
}
}
Expand Down
15 changes: 12 additions & 3 deletions source/Otc.Cache/RedisCacheConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@
{
public class RedisCacheConfiguration : ICacheConfiguration
{
/// <summary>
/// Redis connection string (e.g: http://redis.mycompany.com:30379)
/// </summary>
public string RedisConnection { get; set; }

/// <summary>
/// Time the object will be persisted in cache (in minutes)
/// </summary>
public int CacheDuration { get; set; }

/// <summary>
/// Enable or disable cache configuration
/// </summary>
public bool Enabled { get; set; }

/// <summary>
/// The name os the application that use the Cache abstraction
/// </summary>
public string Aplicacao { get; set; }

public CacheType CacheType { get; }

public RedisCacheConfiguration()
{
CacheType = CacheType.Redis;
}
}
}
3 changes: 0 additions & 3 deletions source/Otc.Cache/SqlCacheConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ public class SqlCacheConfiguration : ICacheConfiguration

public string Aplicacao { get; set; }

public CacheType CacheType { get; }

public SqlCacheConfiguration()
{
CacheType = CacheType.Sql;
}
}
}

0 comments on commit 20fda9f

Please sign in to comment.