I’m thinking of caching permissions for every user on our application server. Is it a good idea to use a SqlCacheDependency for every user?
The query would look like this
SELECT PermissionId, PermissionName From Permissions Where UserId = @UserId
That way I know if any of those records change then to purge my cache for that user.
If you read how Query Notifications work you’ll see why createing many dependency requests with a single query template is good practice. For a web app, which is implied by the fact that you use
SqlCacheDependencyand notSqlDependency, what you plan to do should be OK. If you use Linq2Sql you can also try LinqToCache:For a fat client app it would not be OK. Not because of the query per-se, but because
SqlDependencyin general is problematic with a large number of clients connected (it blocks a worker thread per app domain connected):Updated
Here is the same test as @usr did in his post. Full c# code:
After 50k subscriptions are set up (takes about 5 min), here are the stats io of a single insert:
Inserting 1000 rows takes about 7 seconds, which includes firing several hundred notifications. CPU utilization is about 11%. All this is on my T420s ThinkPad.