문제

I am trying to cache a SQL Stored Procedure with multiple results sets by making use of the SQLCacheDependency class. The first three queries in the stored procedure are queries that are general to all the users on the website, and the fourth retrieves data filtered by the user name.

Since the fourth query in the stored procedure is filtered by the user name, does this mean that the SQLCacheDependency class will remove all the result sets from the Cache each time that another user executes it, or does it mean that it will hit the database to get the results of the fourth query in the stored procedure, and retrieve the results of the first 3 queries from the cache?

Thanks in advance

도움이 되었습니까?

해결책

Since the Application Cache is global (i.e. the same cache is used for all users), what will probably happen is that the first users' results will be cached and served up for all subsequent users. Obviously not the outcome that you want. From the SQLCacheDependency documentation:

the SqlCacheDependency class monitors a specific SQL Server database table. When the table changes, items associated with the table are removed from the Cache, and a new version of the item is added to the Cache.

You should probably separate all 3 of the first queries, cache them independently, and not cache the 4th. Caching is really intended to amortize the cost of an expensive operation (in this case a SQL query) across many users. If you want to store something that is user-specific, that's what Session, Cookies, and ViewState are for.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top