473,396 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

System.Web.Caching and Datasets

I've been reading about the ASP.NET cache object lately out of personal
curiosity and hope someone would enlighten me on a couple points.

It appears the cache object works at application scope, am I right in
assuming that all sessions on the web server will access the same dataset?
For a web site like ours where customers log in to the site this would be a
problem since a new dataset instance is created for each session.

I've traditionally saved the dataset as a session (object Session["myData"]
= myDS; ) before redirecting to a new page to save the dataset. When I open
the new page, I create the dataset from the session object. Would using the
cache instead be quicker and use less code?

Thanks in advance,

Andre
Nov 19 '05 #1
2 1539
You are right about the scope, and you are right that how you are using
DataSets (one per-user) isn't exactly aligned with said scope.

However, you don't use the cache object because it's quicker or uses less
code. Rather you use the Cache because it uses a weak reference and doesn't
pin the data in memory. With the cache you kinda say: Is it in the cache.
No? Then go get it from the source. With the session, once something is
added, you are guaranteed it will stay there for the session's life.

As a side note, you can get around the scope of the cache via the cache key.
string cacheKey = "DataSet:" + userId.ToString()

Karl
--

MY ASP.Net tutorials
http://www.openmymind.net/

"Andre Ranieri" <An**********@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.com...
I've been reading about the ASP.NET cache object lately out of personal
curiosity and hope someone would enlighten me on a couple points.

It appears the cache object works at application scope, am I right in
assuming that all sessions on the web server will access the same dataset?
For a web site like ours where customers log in to the site this would be
a
problem since a new dataset instance is created for each session.

I've traditionally saved the dataset as a session (object
Session["myData"]
= myDS; ) before redirecting to a new page to save the dataset. When I
open
the new page, I create the dataset from the session object. Would using
the
cache instead be quicker and use less code?

Thanks in advance,

Andre

Nov 19 '05 #2
"Andre Ranieri" wrote:
It appears the cache object works at application scope, am I right in
assuming that all sessions on the web server will access the same dataset?
For a web site like ours where customers log in to the site this would be a
problem since a new dataset instance is created for each session.
You are correct. The cache is shared among user sessions. Its the place
where you would store data that is common to all users, such as datasets.
This has the advantage of reducing database load and increasing speed, but it
does require that you take into account the possibility of one user's
modifications of cache objects being seen by another user. That's why all
cached objects should be treated as read only. For instance, in the project
I'm working on, rather than returning datasets from the cache, I return
DataTable.Copy().DefaultView (haven't reached the conclusion that that's the
best solution, tho). I then store the dataview of the copy in each user's
session. A little checking on when said datasets were made and I can assure
that the session holds the freshest data available.
I've traditionally saved the dataset as a session (object Session["myData"]
= myDS; ) before redirecting to a new page to save the dataset. When I open
the new page, I create the dataset from the session object. Would using the
cache instead be quicker and use less code?


No. Storing data in the cache takes the same time and effort that storing
data in the session does. Just remember that you want to keep user specific
data in the session and read-only application specific data in the cache.

What can save you time and code is to abstract your data logic into three
layers -- database, cache, and session. When a page needs data, it requests
it from the session. The session layer looks at the session for the data.
If it is found, its age is compared to the cache data age via the cache
layer. If it is stale, or if it was not found, the data is requested from
the cache layer. The cache layer returns the data from the cache, if found,
or from the database if not. When data is not found in the cache, the cache
layer retrieves it from the database, stores it in the cache (with a callback
method to refresh the data), and returns the data to the session layer. The
session layer then saves the data in the session (updating its age) and
returns the data to the calling page. This is a very simple and straight
forward way to make sure you have the latest data available to your web
pages.
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris Dunaway | last post by:
If I place objects into the cached that implement an IDispose, are they automatically disposed when removed? Looking at the code it doesn't appear so. How can I handle this? Anyone with a...
15
by: olle | last post by:
Hi folks. I learning asp.net and compare it with traditional asp and Access-developing. The issue is this one: 1/I have this Ms Acceess adp-project application that works fine on my Ms Sql...
10
by: BillGatesFan | last post by:
I'm trying to understand ASP.NET caching. I set the Page Output directive to VaryByParams= None and the duration = 60. Now whenever users hit my web app they can see each others data. Is there...
5
by: Raj | last post by:
What is the purpose of file system caching while creating a tablespace? Memory on the test server gets used up pretty quickly after a user executes a complex query(database is already activated),...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.