2

I am experimenting with the utilization of Redis cache in MVC 6 but I can't get my project to build.

I followed the examples at https://github.com/aspnet/Caching/tree/dev/samples - there is an IDistributedCache sample and a Redis sample. However, it's not entirely clear because the Redis sample isn't a web app.

I have this in my project.json dependencies:

    "Microsoft.Framework.Cache.Memory": "1.0.0-beta3",
    "Microsoft.Framework.Caching.Distributed": "1.0.0-*",
    "Microsoft.Framework.Caching.Redis": "1.0.0-*",

I used this to get my packages:

kpm install Microsoft.Framework.Caching.Distributed

and

kpm install Microsoft.Framework.Caching.Redis

Both commands worked and returned an OK.

And in my startup I'm trying the following:

 services.AddSingleton<IMemoryCache, MemoryCache>();
 services.AddSingleton<IDistributedCache, RedisCache>();

When trying to build or run, the error given is:

Startup.cs(10,27): error CS0234: The type or namespace name 'Caching' does not exist in the namespace 'Microsoft.Framework' (are you missing an assembly reference?) Startup.cs(11,27): error CS0234: The type or namespace name 'Caching' does not exist in the namespace 'Microsoft.Framework' (are you missing an assembly reference?) Startup.cs(25,35): error CS0246: The type or namespace name 'IDistributedCache' could not be found (are you missing a using directive or an assembly reference?) Startup.cs(25,54): error CS0246: The type or namespace name 'RedisCache' could not be found (are you missing a using directive or an assembly reference?)

Now obviously I have the wrong references - but what are the right references? I'm copying the namespaces directly from the samples? I tried switching to Microsoft.Cache.Distributed and that didn't work either (and conflicted with github)

I have a feeling this is to do with not having the correct K version and maybe that's the way out - upgrading to the latest version. There is a mismatch between Framework.Cache.Memory and Framework.Cache.Distributed and I see github comments relating to namespace changes.

If anyone can point the way out of this maze, much appreciated.

2
  • try beta4 instead beta3 Commented May 19, 2015 at 13:53
  • beta4 specifically where - for the whole project? Commented May 19, 2015 at 14:16

1 Answer 1

1

The below answer applies for 1.0.0-beta4 release of caching library which corresponds to here: https://github.com/aspnet/Caching/tree/1.0.0-beta4

IMemoryCache is under Microsoft.Framework.Caching.Memory namespace and IDistributedCache is under Microsoft.Framework.Caching.Distributed namespace.

Dependencies would look like this:

"dependencies": { 
    "Microsoft.Framework.Caching.Memory": "1.0.0-beta4",
    "Microsoft.Framework.Caching.Distributed": "1.0.0-beta4",
    "Microsoft.Framework.Caching.Redis": "1.0.0-beta4"
}

So, Microsoft.Framework.Cache.Memory is Microsoft.Framework.Caching.Memory.

Sign up to request clarification or add additional context in comments.

3 Comments

The issue is that those namespaces are not resolving. If you see my project.json references, I have those in (they are also stated as 'using' statements in the startup.cs file).
I have tried this but unfortunately hosed my entire install. Also tried going from KRE to DNX and failed at that as well. Jumping from beta3 to beta4 has been fatal. I'll have to work through it and come back when I clear the decks and get what I had running again.
Ok this works I finally got it going. A question though - is there any other Distributed caching implementations except for Redis?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.