Multiple Databases with same entity name

May 3, 2016 at 3:01 PM

I have a web application in which users are set up to use databases on different servers.

User User1 is set up to use the application database on server Alpha
User User2 is set up to use the application database on server Beta

and so on for about 12 instances. Each database has the same schema.

My problem is that when a user writes a cache key for database Alpha, it overwrites the key for my users in database Beta.

How can I either marshall the cache to go to a different Redis database, based on the server name, or otherwise differentiate the keys based on server name? I assume this would need to be done in an override of the CacheTransactionHandler?

Thanks for any advice
May 5, 2016 at 5:55 AM
If I understand your scenario correctly you have12 database but just one cache. Since entity names are the same the results get overwritten and the clients can get result saved by different clients.
Currently EF Cache does not use database/connection string as part of the cache key. This is why results can be overwritten/removed from the cache even though they come from a different database. On the other hand if you are using X databases it might be better to use X caches (not sure if this is feasible in your case). Not sharing a single cache instance may scale better and removes single point of failure. I don't know how you configure your application but if you are using app/web.config and set the connection string there you could add configuration settings for the Redis instance that you want to use and use it when initializing cache.

I am not sure how useful it is but there was a similar thread a while ago you may want to take a look at.