Skip to content

Commit

Permalink
Fixing QueryCache
Browse files Browse the repository at this point in the history
Fixing QueryCache
  • Loading branch information
zzzprojects committed Sep 13, 2016
1 parent 6795c71 commit 6bf5f92
Show file tree
Hide file tree
Showing 43 changed files with 1,086 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("e4c2af73-caeb-4429-bcb6-0a359484e064")]
[assembly: AssemblyVersion("1.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

#if EF5 || EF6
using System;

#if EF5 || EF6
using System.Runtime.Caching;

#elif EFCORE
Expand Down Expand Up @@ -40,9 +41,17 @@ public static T FromCache<T>(this QueryDeferred<T> query, CacheItemPolicy policy
if (item == null)
{
item = query.Execute();
item = QueryCacheManager.Cache.AddOrGetExisting(key, item, policy) ?? item;

item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, policy) ?? item;
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T) item;
}
Expand All @@ -68,9 +77,17 @@ public static T FromCache<T>(this QueryDeferred<T> query, DateTimeOffset absolut
if (item == null)
{
item = query.Execute();
item = QueryCacheManager.Cache.AddOrGetExisting(key, item, absoluteExpiration) ?? item;

item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, absoluteExpiration) ?? item;
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T) item;
}
Expand Down Expand Up @@ -111,9 +128,17 @@ public static T FromCache<T>(this QueryDeferred<T> query, MemoryCacheEntryOption
if (!QueryCacheManager.Cache.TryGetValue(key, out item))
{
item = query.Execute();
item = QueryCacheManager.Cache.Set(key, item, options);

item = QueryCacheManager.Cache.Set(key, item ?? DBNull.Value, options);
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T)item;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

#if NET45
using System;
using System.Threading.Tasks;

#if EF5 || EF6
using System;
using System.Runtime.Caching;

#elif EFCORE
Expand Down Expand Up @@ -44,9 +45,16 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, CacheItemPo
if (item == null)
{
item = query.Execute();
item = QueryCacheManager.Cache.AddOrGetExisting(key, item, policy) ?? item;
item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, policy) ?? item;
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T) item;
});
Expand Down Expand Up @@ -77,9 +85,16 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, DateTimeOff
if (item == null)
{
item = query.Execute();
item = QueryCacheManager.Cache.AddOrGetExisting(key, item, absoluteExpiration) ?? item;
item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, absoluteExpiration) ?? item;
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T) item;
});
Expand Down Expand Up @@ -125,9 +140,16 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, MemoryCache
if (!QueryCacheManager.Cache.TryGetValue(key, out item))
{
item = query.Execute();
item = QueryCacheManager.Cache.Set(key, item, options);
item = QueryCacheManager.Cache.Set(key, item ?? DBNull.Value, options);
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T)item;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

#if EF5
using System.Runtime.Caching;
using System.Data.EntityClient;
using System.Data.SqlClient;

#elif EF6
using System.Data.Entity.Core.EntityClient;
using System.Data.SqlClient;
using System.Runtime.Caching;

#elif EFCORE
Expand Down Expand Up @@ -182,6 +183,7 @@ public static string GetCacheKey(IQueryable query, string[] tags)
}

sb.AppendLine(string.Join(";", tags));
sb.AppendLine(query.Expression.ToString());
sb.AppendLine(command.CommandText);

foreach (var parameter in queryContext.ParameterValues)
Expand Down Expand Up @@ -261,6 +263,7 @@ public static string GetCacheKey<T>(QueryDeferred<T> query, string[] tags)
}

sb.AppendLine(string.Join(";", tags));
sb.AppendLine(query.Expression.ToString());
sb.AppendLine(command.CommandText);

foreach (var parameter in queryContext.ParameterValues)
Expand Down
4 changes: 2 additions & 2 deletions src/Z.EntityFramework.Plus.EF5/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("abcbb878-043c-4957-a334-90e9872e684e")]
[assembly: AssemblyVersion("1.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

#if EF5 || EF6
using System;

#if EF5 || EF6
using System.Runtime.Caching;

#elif EFCORE
Expand Down Expand Up @@ -40,9 +41,17 @@ public static T FromCache<T>(this QueryDeferred<T> query, CacheItemPolicy policy
if (item == null)
{
item = query.Execute();
item = QueryCacheManager.Cache.AddOrGetExisting(key, item, policy) ?? item;

item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, policy) ?? item;
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T) item;
}
Expand All @@ -68,9 +77,17 @@ public static T FromCache<T>(this QueryDeferred<T> query, DateTimeOffset absolut
if (item == null)
{
item = query.Execute();
item = QueryCacheManager.Cache.AddOrGetExisting(key, item, absoluteExpiration) ?? item;

item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, absoluteExpiration) ?? item;
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T) item;
}
Expand Down Expand Up @@ -111,9 +128,17 @@ public static T FromCache<T>(this QueryDeferred<T> query, MemoryCacheEntryOption
if (!QueryCacheManager.Cache.TryGetValue(key, out item))
{
item = query.Execute();
item = QueryCacheManager.Cache.Set(key, item, options);

item = QueryCacheManager.Cache.Set(key, item ?? DBNull.Value, options);
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T)item;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

#if NET45
using System;
using System.Threading.Tasks;

#if EF5 || EF6
using System;
using System.Runtime.Caching;

#elif EFCORE
Expand Down Expand Up @@ -44,9 +45,16 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, CacheItemPo
if (item == null)
{
item = query.Execute();
item = QueryCacheManager.Cache.AddOrGetExisting(key, item, policy) ?? item;
item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, policy) ?? item;
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T) item;
});
Expand Down Expand Up @@ -77,9 +85,16 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, DateTimeOff
if (item == null)
{
item = query.Execute();
item = QueryCacheManager.Cache.AddOrGetExisting(key, item, absoluteExpiration) ?? item;
item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, absoluteExpiration) ?? item;
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T) item;
});
Expand Down Expand Up @@ -125,9 +140,16 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, MemoryCache
if (!QueryCacheManager.Cache.TryGetValue(key, out item))
{
item = query.Execute();
item = QueryCacheManager.Cache.Set(key, item, options);
item = QueryCacheManager.Cache.Set(key, item ?? DBNull.Value, options);
QueryCacheManager.AddCacheTag(key, tags);
}
else
{
if (item == DBNull.Value)
{
item = null;
}
}

return (T)item;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

#if EF5
using System.Runtime.Caching;
using System.Data.EntityClient;
using System.Data.SqlClient;

#elif EF6
using System.Data.Entity.Core.EntityClient;
using System.Data.SqlClient;
using System.Runtime.Caching;

#elif EFCORE
Expand Down Expand Up @@ -182,6 +183,7 @@ public static string GetCacheKey(IQueryable query, string[] tags)
}

sb.AppendLine(string.Join(";", tags));
sb.AppendLine(query.Expression.ToString());
sb.AppendLine(command.CommandText);

foreach (var parameter in queryContext.ParameterValues)
Expand Down Expand Up @@ -261,6 +263,7 @@ public static string GetCacheKey<T>(QueryDeferred<T> query, string[] tags)
}

sb.AppendLine(string.Join(";", tags));
sb.AppendLine(query.Expression.ToString());
sb.AppendLine(command.CommandText);

foreach (var parameter in queryContext.ParameterValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("ac398eb8-0a31-4d06-a804-84d10b6da96d")]
[assembly: AssemblyVersion("1.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.4.1")]
[assembly: AssemblyFileVersion("1.4.1")]
Loading

0 comments on commit 6bf5f92

Please sign in to comment.