Azure - what is the purpose of applicationName in Azure Caching? - caching

Configuration the ASP.NET Output Cache Provider for Windows Azure Caching
I'm a bit confuse about applicationName attribute.
Does it mean I can use multiple applications share the same Azure cache (as long as I don't max out Transactions, Data Transfers and Connections)?
In other words, same cache key won't collide between different web applications as long as applicationName are different?
1 GB cache for $110.00 is a lot cheaper than 10 X 128 MB cache for $45.00.
Thank you for shedding the light!

If we consider the architectural design for out-of-box cache, so when you have multiple instances of same application running in cloud and using a out-of-box cache, to keep all of the instances in sync with regard to output cache.
When you have multiple applications 1) / Root 2) /production 3) /test you really don't want to mix output cache between two different applications because output cache could have full page and partial page cache distributed at cache endpoint based on application name (if configured) or AppID provided by the IIS system.
IF you are using multiple sites within the same ASP.NET Web Role application then you can use dataCacheClient to separate output cache based on different host headers for different sites withing the same application, that would be preferred solution.

Based on the MSDN link, the ApplicationName is used internally to generate the Cache Key. If application key is not provided it uses HttpRuntime.AppDomainAppId. Now the onus is on the development team to udpated IIS metabase so that HttpRuntime.AppDomainAppId in each instance resolves to same value.
In short ApplicationName name is used to provide an additional layer of segregation, If ApplicationName match in different apps, those apps would use the same cache.

The difference in usage of applicationName tag for session state and output caching is mentioned here:
http://msdn.microsoft.com/en-us/library/hh361708.aspx
In context to the question asked here, applicationName tag is handy to cache data between multiple instances of the same role.

Related

Setting Up Ncache (Distributed?/Shared)

I have two servers, where I will be deploying the same application. Basically these two servers will handle work from a common Web API, the work that handed out will be transformed and go through some logic and loaded into DB. I want to cache the data the get loaded/update or deleted in the database, so that when the same data is referenced i can get it from the Cache (Kind of explained the cache mechanism). Now I am using Ncache and it working perfectly fine within one application. I am trying have kind of a shared cache, so that both my application can have access to. How do i go about doing it?
NCache is a distributed cache so you can continue to use that.
There is good general documentation available and very good getting started material that walks you through all the steps required.
In essence you install NCache on both the servers and then reference both servers in your client configuration (%NCHOME%\config\client.ncconf)
In cluster caches, a single logical cache instance is distributed over multiple server nodes and because the cache process is running outside the application address space, multiple applications can share and see the same exact cache data change in terms of addition, removal and update of the cache content.
Local out-proc caches are limited to one server node but as they are outside the application address space, they also support sharing of data between applications.
In fact, besides allowing multiple applications to share data, NCache supports a pub/sub infrastructure to allow for multiple applications to actually communicate with each other. This allows NCache to play a key part in setting up a fast and reliable microservices environment wherein all the participating services send messages to each other through the NCache platform.
See the link below where they have shared information about NCache topologies
http://www.alachisoft.com/resources/docs/ncache/admin-guide/cache-topologies.html
http://www.alachisoft.com/resources/videos/five-steps-getting-started.html

Caching for both Angular and ASP .NET MVC

Background
In my project app, many small applications has been integrated and they have built-in different technologies such as
Angular JS 1.5
ASP.Net MVC
Angular 5
My app also uses AWS as cloud partner.
Problem
I need to implement Caching mechanism in my app. I am storing some values in S3 bucket and I am using API calls to pull the values. I want to keep those values in Cache. Since, it is implemented in multiple technologies (especially Angular and ASP.Net MVC), Does any caching mechanism can be used in common?
Observations
I have done some work on this and observed the following caching is available
.NET MVC - In Memory Caching
Angular - In Memory Cache with ReactJS
As AWS is my Cloud Partner, it is offering ElastiCache as a Web service, which supports MemCached and Redis. I am not clear whether this will behave like normal In-Memory Cache ( in ASP .NET Core) or this will refer database for caching and retrieve details (cause round-trip!) from there?
Question
Can anyone let me know best caching technique can be handled to my app for both .net mvc and angular?
This is bit tricky (I am assuming that you are using multiple servers of memcache). When you use memcache a lot depends on the clients implementation. Your client decides, on which server a particular key will be stored. And the servers are unaware of the existences of the other servers.
As you are using different languages you will be using different clients so each client will be implementing its own algorithm to decide the server on which the key will be placed. So there will be cases where your client on Angular will store key "K1" on server "S1" and the .Net Client will store the same key on server "S2"
This will add another problem of invalidating these keys, as it will be needed to invalidate the key on both servers.
There is one more problem. You will have to store all objects in a json format if the keys are common. So that the keys is stored on the same memcache server will be read by all programing languages.
I think the best thing is to set a small enough time to invalidate keys on memcache (if it is feasible) and storing keys with different prefix or suffix for each client type. So .net client will store key K1 as 'K1-net' and the one with Angular will store it as "k1-ang".
I would also explore redis which might help (not sure)

How to limit memory/item size in a named cache in windows app fabric cache?

I am relatively new to .net / windows technologies and I need to use appfabric cache for a project.
After spending some time, I feel that one of the basic functionalities of a cache framework, namely limiting the size of a cache, is absent in the appfabric caching framework. I know that popular java caching frameworks like ehcache and hazelcast has this functionality through xml configuration elements (maxElementsInMemory attribute in ehcache , max-size attribute in hazelcast).
I know that this question has been asked previously in a similar form:
How to set Windows Server AppFabric named cache size?
However, I could not find a conclusive proposal to limit cache size per named cache basis in app fabric.
I need to expose caching apis to several application development groups. Each group is supposed to be assigned their own named cache but I need a mechanism to prevent cache abuse. Each cache user should live with their own limited named cache space. I.e they should not consume more memory than the amount reserved for them.
I do not want to write ugly custom code in my api to limit this and I believe that this is a basic requirement that a caching framework should support.
Any proposal for how to achieve this in app fabric will highly be appreciated.
Thanks

Windows Azure in-role caching vs shared cache

We have a website in Azure and we want to cache the content on the website. The app that will update the content will be outside Azure. We got this scenario working with Shared Cache. Shared caching however is considered a legacy feature and so we wanted to take a look at alternate solutions including using in-role caching. The cached content is very small should not exceed 1 MB and will be consumed by C# code.
We could use co-located cache within the web roles or dedicated cache using a worker role.
The questions we had using in-role cache are:
How can the co-located cache be updated from an external app?
If there was a way to update co-located cache from an external app,
cache notifications could be used to invalidated all co-located cache nodes, correct?
We use extra-small web role instances now - do we need to upgrade to
small/medium instances?
Is dedicated caching better for our scenario?
Thanks in advance.
After doing a bunch of research and guided by Simon's responses in the SO thread he already mentioned, here are my responses:
Q: How can the co-located cache be updated from an external app?
A: I would expose a public endpoint on your Webrole that would clear cache. And I would call that endpoint from your external apps (this endpoint can be a service, rest URL, etc). Alternatively, throw a message onto a queue and have your Webroles monitor that queue and clear the item from cache when they receive a message in the queue. Either way, you're implementing your own notification mechanism
Q: If there was a way to update co-located cache from an external app, cache notifications could be used to invalidated all co-located cache nodes, correct?
A: I don't believe so. The endpoints to co-located cache are strictly internal.
Q: We use extra-small web role instances now - do we need to upgrade to small/medium instances?
A: Yes. I believe colocated cache is supported at Small instance and higher. You will need to try this out to see how much ram you get vs. how much is left over and whether or not that is of any use to your main application
Q: Is dedicated caching better for our scenario?
A: Dedicated vs. colocated cache is really about the load. Do you
have enough load on your cache and on your app servers to justify
moving the cache out into a separate Role? Check out this article
for Microsoft's recommendation:
http://msdn.microsoft.com/en-us/library/windowsazure/hh914129.aspx

What level is ObjectCache at

If I add an object to the ObjectCache - at what level is this stored at? Would this be accessible by all users of the application or only a specific instance?
I've read articles that claim it is at application level but when I enumerate the cache, all I can see are the objects that instance of the application created.
As far as I know it depends on the application pool (since it stays on top of the ASP.NET stack).
This means that if you have multiple instances of the same cache on the same machine, each using a different app pool, you'll have different caches. The same if you have multiple machines.
If you want a single cache on multiple machines use a distributed cache like Windows Server Appfabric.

Resources