Git Product home page Git Product logo

caching's People

Contributors

ajaybhargavb avatar aspnetci avatar billpratt avatar brennanconroy avatar bricelam avatar chengtian avatar d-saravanan avatar davidfowl avatar dougbu avatar eilon avatar halter73 avatar haok avatar javiercn avatar juntaoluo avatar kichalla avatar mikaelm12 avatar mikeharder avatar natemcmaster avatar ntaylormullen avatar pakrym avatar pranavkm avatar ryanbrandenburg avatar sebastienros avatar smitpatel avatar sonjakhan avatar staff0rd avatar tratcher avatar troydai avatar tstanitz avatar unaizorrilla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

caching's Issues

Access Cache globally in ASP.NET 5

Hello,
In ASP.NET 4, we can always get Cache instance by using HttpContext.Cache.
What's the similar solution for me to get this kind of global cache access in all my Controllers and Middlewares in ASP.NET 5?

Thanks lot
Gary

Redis Mac OSX Error

I have the following error when trying to connect to networks from Mac OSX (Mono 4.2 ,dnx rc-1-final)

An unhandled exception has occurred: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING
StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING
at StackExchange.Redis.ConnectionMultiplexer.Connect (System.String configuration, System.IO.TextWriter log) <0x6ef60f0 + 0x00113> in :0

in Windows 10 I have no problem

Redis cache does not implement Microsoft.Extensions.Caching.Distributed.IDistributedCache

Good morning,

I was trying to implement Sessions and Caching using Redis.

The framework is dnx451 and the versions of the packages are:
"Microsoft.Framework.Caching.Redis": "1.0.0-rc1-15658",
"Microsoft.AspNet.Session": "1.0.0-rc1-final"

RedisCache implements the interface Microsoft.Framework.Caching.Distributed.IDistributedCache but in order to use RedisCache for session, it needs to implement Microsoft.Extensions.Caching.Distributed.IDistributedCache which has a very similar contract, but not exactly the same.

In order to acomplish that, I have implemented my own class as follows:
public class OwnRedisCache : RedisCache, IDistributedCache
{
public OwnRedisCache(IOptions optionsAccessor) : base(optionsAccessor)
{
}

    public void Set(string key, byte[] value, DistributedCacheEntryOptions options)
    {
        base.Set(key, value, new Microsoft.Framework.Caching.Distributed.DistributedCacheEntryOptions());
    }

    public Task SetAsync(string key, byte[] value, DistributedCacheEntryOptions options)
    {
        return base.SetAsync(key, value, new Microsoft.Framework.Caching.Distributed.DistributedCacheEntryOptions());
    }
}

Is it possible or are you planning to modify the RedisCache class so it implements both interfaces?

Code to a full implementation can be found on https://github.com/joaquin-corchero/MVC6RedisSessionAndCache

Cheers

Please add ISignal by default

There is an implementation here: https://github.com/aspnet/Mvc/blob/dev/test/WebSites/HtmlGenerationWebSite/ISignalTokenProviderService.cs

I can copy it but I would suggest to add it OOB. The scenario is that multiple keys might depend on the same logical dependency, and this is a way to invalidate all of them. It's a very common used pattern in Orchard, so I assume it would be to with other applications using IMemoryCache.

I understand it might also have been intentionally kept out too.

/cc @lodejard

Why use caching.redis?

Why should I use microsoft.framework.caching.redis (that has a dependency on stackexchange.redis) instead of just using the functionality already available in stackexchange.redis?

Bug of caching

Error

   at Microsoft.Extensions.Caching.Memory.CacheExtensions.TryGetValue[TItem](IMemoryCache cache, Object key, TItem& value)
   at Microsoft.Data.Entity.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.Data.Entity.Query.Internal.QueryCompiler.CompileQuery[TResult](Expression query)
   at Microsoft.Data.Entity.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.Data.Entity.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at Remotion.Linq.QueryableBase`1.GetEnumerator()
   at Microsoft.Data.Entity.Internal.InternalDbSet`1.System.Collections.Generic.IEnumerable.GetEnumerator()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at ITN.TS.Administrator.Controllers.ContentController.AddContent(Int32 id, Int32 parent, Boolean viewMode) in D:\Givi\ITN.TS.FW\src\ITN.TS.Web\Modules\ITN.TS.Administrator\Controllers\ContentController.cs:line 84.

getting null on Get (question)

Either I am not understanding the purpose of MemoryCache or I am doing something wrong.
My goal is to use it to cache items in memory across multiple requests in my mv6 app.

I check to see if its null, if it is then I get my stuff from db and set it in the Index of home controller, then I try to access that from a ajax call but i always get null.. here is my code..

  public IActionResult Index()
        {
            IMemoryCache cache = new MemoryCache(new MemoryCacheOptions());
            if (cache.Get("searchList") == null)
            {
                var connectionString = "...";
                using (var conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    var SQL = "SELECT * FROM SearchView";
                    var reader = SqlHelper.ExecuteReader(conn, CommandType.Text, SQL, null);

                    List<SearchResult> results = new List<SearchResult>();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {

                            results.Add(new SearchResult
                            {
                                Type = reader.GetInt32(0),
                                Description = reader.GetString(1)
                            });
                        }
                    }

                    var result = cache.Set("searchList", results, new MemoryCacheEntryOptions().SetPriority(CacheItemPriority.NeverRemove));

                }

            }
            return View();
        }

then in my access method for ajax

  public IActionResult GetSearchResultUsingCache(string query)
        {
            IMemoryCache cache = new MemoryCache(new MemoryCacheOptions());
            var all = cache.Get("searchList");
}

the variable "all" is always null

IMemoryCache should support async factory callbacks

The cache is used to avoid repeated expensive operations. The main method for adding anything to the cache (Set) takes a callback factory to do said expensive work and configure the cache settings. This factory won't be called from GetOrAdd if the entry is already present.

Proposal: Because this object creation work can be expensive we should support doing it asynchronously. E.g. Task<object> SetAsync(string key, Func<ICacheAddContext, Task<object> factory);

Workaround: Today you can cache a Task<T>, but that could also end up caching failure conditions.

Remove Connect and ConnectAsync methods from IDistributedCache interface

@lodejard brought up a good point of the need of having a Connect method on the interface. They seem to be implementation details for the particular distributed cache implementation (ex: RedisCache). SqlServerCache and LocalCache(distributed MemoryCache) do not require them.

https://github.com/aspnet/Caching/blob/dev/src/Microsoft.Extensions.Caching.Abstractions/IDistributedCache.cs#L10-L12

cc @Tratcher @muratg @Eilon @davidfowl

And regarding related issue #131, RedisCache can implement an IDisposable interface and in the dispose method can close the connections. Currently RedisCache is registered as singleton and the DI would call the Dispose method on the singleton instance(I verified this is happening)

Small perf wins inside MemoryCache

Hi, I was looking at the caching code and I found some points which can be enhanced to avoid creating unnecessary objects. I'm referring to the class MemoryCache, the private field _entries can be a Dictionary<string, CacheEntry> instead of anIDictionary<string, CacheEntry> (since it's private and it's always initialized to a Dictionary<string, CacheEntry>) thus saving some unnecessary memory allocation when iterating over Keys and Values. Also the RemoveEntries method could be changed to accept a List instead of IEnumerable<CacheEntry> (since it's a private method always called with an instance of List<CacheEntry>) saving 1 object allocation when iterating over the list of entries. This change will also be consistent with the method ExpirePriorityBucket which already accept generic lists parameters.

It's not a huge improvement, but it's a fairly simple one at least IMHO.

Max.

The caching architecture is a mess

Hey guys,

I have been trying to figure out the hierarchy around the caching framework.
So far everything seems to be a huge mess:

  1. LocalCache implements IDistributedCache which does not make any sense.
  2. IDistributedCache works with byte[] but there is no binary serializer in .NET Core.
  3. MemoryCache implements IMemoryCache which does not inherit from a more generic caching interface.

I have been trying to wrap a local in-memory cache which I should be able to replace by changing the cache which I am using. However, I find it quite difficult to use LocalCache because it requires a binary serializer which is an unnecessary overhead and there isn't a build-in one in .NET Core anyway. I cannot wrap directly MemoryCache because the interface it implements basically means that I will be stuck using an in-memory cache and I will not be able to switch at a later point.

I am sorry if I sound too harsh but the current architecture is a mess. Please fix/rewrite this architecture before you release a final version and we get stuck with something which cannot be changed because it will require breaking changes.

Rename EntryLinkHelpers.ContentLink

CacheTagHelpers in Mvc rely on this API for users to be able to set custom triggers as part of their code. It would be nice to have the type name be less obtuse. Maybe CacheEntry.CurrentContext?
cc @DamianEdwards

Multiple Redis cache instances

Is it possible to create multiple instances of the RedisCache class where each instance connects to a different server/instance of Redis?

As far as I can see that the RedisCache class doesn't support named options, hence I presume that all instances have to use the same configuration.
Thanks

sqlservercache command fails to run due to runtime compatibility check

C:\>sqlservercache
System.InvalidOperationException: The current runtime target framework is not compatible with 'app'.
Current runtime target framework: 'DNX,Version=v4.5.1 (dnx451)'
 Version:      1.0.0-rc1-16231
 Type:         Clr
 Architecture: x64
 OS Name:      Windows
 OS Version:   10.0
 Runtime Id:   win10-x64

Please make sure the runtime matches a framework specified in project.json
   at Microsoft.Dnx.ApplicationHost.DefaultHost.GetEntryPoint(String applicationName)
   at Microsoft.Dnx.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args)
   at Microsoft.Dnx.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at Microsoft.Dnx.Host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env, String appBase, FrameworkName targetFramework)
   at Microsoft.Dnx.Host.RuntimeBootstrapper.ExecuteAsync(String[] args, BootstrapperContext bootstrapperContext)
   at Microsoft.Dnx.Host.RuntimeBootstrapper.Execute(String[] args, BootstrapperContext bootstrapperContext)

Support a conditional add mechanic

In the GetOrAdd scenario the object creation factory is called and the resulting value is cached. However, the factory may determine that there is no data available to cache. Today even null returned values are cached, so the factory needs some other way to indicate not to cache the value.

Proposal: Support a conditional factory that returns true/false indicating if there is something to add to the cache. e.g. bool TryGetOrAdd(string key, out object obj, Func<ICacheAddContext, out object, bool>).

Workaround: The factory could throw an exception to prevent caching, but this is ugly and expensive:

try
{
   var result = cache.GetOrAdd(key, context => 
   {
     ...
     throw new InvalidOperationException("No data available to cache");
   });
}
catch (InvalidOperationException) {}

Where's is the simple TSQL script for creating the CacheTable

Hi team,
There's a TableName parameter to define the table used by SQLCache.
I searched online, it seems I have to call DNX commands somehow to create tables. and there's other document about how to make DNX ready. I think it is too complex and unnecessary.
I guess the script for table (maybe some stiredprocedures and triggers) must be very straightforward. could you provide the whole TSQL for creating the table and other database objects in a file on github? So developers can simply run it by themselves?

Cheers
Gary

Unable to instantiate MemoryCache via DI

MemoryCache has two constructors, MemoryCache() and MemoryCache(ISystemClock clock, bool listenForMemoryPressure). The second one is just for testing purposes, but it causes problems with DI.

The following doesn't work because DI tries to call the second constructor:

            app.UseServices(collection =>
            {
                collection.AddSingleton<IMemoryCache, MemoryCache>();
            });

You have to do it this way instead:

            app.UseServices(collection =>
            {
                collection.AddInstance<IMemoryCache>(new MemoryCache());
            });

This isn't a huge problem yet because it doesn't take any services, but it may become a problem when we add telemetry support.

Microsoft.Framework.Expiration.Interfaces namespace has just one type

The Microsoft.Framework.Expiration.Interfaces namespace has just one type: IExpirationTrigger

https://github.com/aspnet/Caching/blob/dev/src/Microsoft.Framework.Caching.Abstractions/IExpirationTrigger.cs#L6

And what a weird namespace name, too.

it appears to be used within caching, and also within the FileSystem repo to implement the file watcher notifications, e.g.:

I don't have a specific suggestion on what it should be, but I don't think it can stay as is. Perhaps it goes to the main Caching namespace? (And we get rid of the unnecessary .Interfaces namespace suffix as well.)

Need an expiration Trigger for file changes

We expect one very common use of the cache will be to cache files in memory until they are modified on disk. Create an expiration trigger that can monitor for file changes.

Also, consider adding some extensions that will read the file in for you and hook up this trigger by default.
string GetOrAddFileText(string key, string filename)
byte[] GetOrAddFileBytes(string key, string flename)

IDistrbutedCache Extension Methods/Helper Methods

The IDistrbutedCache seems pretty basic at the moment compared to the IMemoryCache, as it only deals in byte arrays. Most developers using this interface will be writing some extensions methods for it.

This StackOverflow post is asking if these methods will eventually be part of ASP.NET Caching or if we should role our own.

The BinaryFormatter is not available in .NET Core, is it going to be added in future? In the mean time the BinaryWriter and BinaryReader seem to be the way to go. I might just submit a pull request this evening.

See the StackOverflow post for the proposed extension methods.

Key for memory cache should be of type object instead of string

There doesn't seem to be a good reason for it to be constrained to string and object could have a number of advantages, e.g.:

  • Perf: no need to compute a string based on individual components
  • Easier to avoid collisions by having separate key types
  • Potentially easier to add (and read) metadata to (from) the key
  • Encapsulation: cache key can be made non-public, forcing other components to not sniff directly into the cache but talk to the right layer

cc @lodejard @davidfowl and @anpete

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.