ComponentOne WebData for ASP.NET:Using WebDataObjects for ASP.NET Components > Global Cache

Global Cache

The global cache is the default caching mode, it is used by default for every WebDataObjects for ASP.NET data set if you don't change cache settings and don't call SessionCache methods. To disable caching for a data set completely, set CacheMode = NotCached.

The global cache is a common storage on the server for your Web application serving all requests from all users while preserving the changes made by an individual user. When a data set is filled with data from database, the fetched data is stored in the cache for later use, together with information about user request, such as the filter condition used to fetch data. When another request for the same data set with the same filter condition arrives from the same or another user later on, cached data is used to fill the data set instead of fetching data from the database.

If the user modifies data, the global cache stores user modifications and then applies them automatically to the cached or fetched data next time a request arrives from the same user, to preserve the consistency of this user's view of modified data. The users' responsibility is to call SaveChanges after they are done with modifying data; this enables global cache to save this user's changes for future use.

Comparing with session cache, the global cache has the advantage of scalability, because data is stored without duplication. Same data fetched by multiple users is stored only once. It can also improve performance, because when one user fetches some data and then the same request (with the same filter condition if one is specified) arrives from a different user, the second user's request will likely be served by the cache, without database fetch. The global cache is particularly effective when you have relatively large data sets (so it is not practical to store them in the session cache) with modifiable tables and filter conditions used in requests are likely to repeat themselves. Read-only (non-modifiable) tables are best represented as memory-resident, see Memory-resident Table Views, but you can make one or more table views memory-resident and store the rest in the global cache (or in the session cache). You can also store some data sets in the global cache, some in the session cache, and make others not cacheable.

On the other hand, the global cache has a disadvantage (or rather a feature that can be detrimental in some cases, though neutral or even beneficial in others) with respect to the session cache in that the data received by the same user can change between requests due to changes in the database made by other users. In the session cache, each user's data set is stored separately, so they don't feel any changes made by others until the whole data set is re-fetched from the database. In the global cache, a user is guaranteed to receive the same data for same requests until another user updates the database. At the time of database update, all global cache data pertaining to this data set is cleared, so it is fetched from the database next time it is requested by any user. However, it is important to understand that this only affects rows that have not been changed by the user. The global cache guarantees that users always see modified rows intact, cannot lose their modifications under any circumstances. The fact that unmodified rows can change between requests simply means that the user sees the most recent rows from the database, excluding rows modified by the same user, which appear locked, owned by the user until they are committed to the database.


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.