[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Caching across pages and some other stuff

Posted on 2005-05-10
7
Medium Priority
?
187 Views
Last Modified: 2010-04-07
Hi,

I was wondering how I access cached objects across multiple pages.  Does Page.Cache.Insert only refer to the current page and not across other pages?  If so, how can I make this possible?  Also, what is the difference between:

Page.Cache.Insert("contractTypeCol", contractTypeCol);
and
HttpContext.Current.Cache["contractTypeCol"] = contractTypeCol

Seems like they are both doing the same thing.
I guess I am not really sure what HttpContext and Current means and MSDN is not much help.

thanks



0
Comment
Question by:brdrok
  • 3
  • 3
7 Comments
 
LVL 26

Expert Comment

by:Rejojohny
ID: 13969280
both r the same .. both references the sytem.web.caching.cache object .. whatever u store in the cache is accessible across pages .. it is just like a application object .. accessible by all users .. it has some additional parameters like the time when it will expire, priority etc which helps in managing these objects more efficiently than application objects ...
0
 
LVL 7

Author Comment

by:brdrok
ID: 13969377
hmmm....so the page.cache vs. HttpContext.Curent is only a matter of prefrence?  

You know how one can do dependencies (i.e. on xml files) and depending on whether the xml file changes, it evicts the current object inside that cache?  what I was wondering is whether somehting like this would apply to strongly typed collections.  so, if i had an cached object based on a a collection object i called "colContractTypes", and someone/somewhere/somehow added a new object, would that mean my collection object would be evicted from my cache?

thank you....
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 1600 total points
ID: 13969540
>>HttpContext.Curent is only a matter of prefrence?  
its not just a matter of preference .. but also depends on how and where u r accessing it .. do not ask me y, but i had problems accessing cache stored using web pages in web services .. unless i used httpcontext.current ... anyway as for the the dependency of a cache object, i not think it is possible to associate it to a class .. it has to be a physical object .. or another object in the cache ..
this is what MSDN says

CacheDependency Class
Tracks cache dependencies, which can be files, directories, or keys to other objects in your application's Cache.

so u could add the object "colContractTypes" to cache and have this as a dependency to another cache ..
>>and someone/somewhere/somehow added a new object, would that mean my collection object would be evicted from my cache?
this object should always update the cache .. then ur other cache will also change .. but then in that case y would u require 2 cahche object .. right? unless u plan to have 2 different views of the same object ...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Author Comment

by:brdrok
ID: 13969724
clear as mud =)

thanks very much for your insight....and i truly wish i could assign more points to this question.  hmm...having a cache object act as a dependency for another cache object seems a little too funky for me given my skill level.

what precipated all this is the following scenario:  I have two drop down list boxes and the second drop down listbox values are dependant on the selected value of the first.

using my favorite example =) I have various departments and each department would have employees associated with one single department.

since the department collection doesn't change very often (if at all), i thought this would be a great candidate for caching.  depending on the department selected, the second drop down list box will list all the employees for that employee.  do you think I should create a cache object that will hold the employees for each department (i.e.

Page.Cache.Insert("MusicDeptEmployeesCollection", colMusicDeptEmp);
Page.Cache.Insert("EnglishDeptEmployeesCollection", colEngDeptEmp);
Page.Cache.Insert("PhysicsDeptEmployeeCollection", colPhysicsDeptEmp);

hope this made sense....
0
 
LVL 5

Assisted Solution

by:Qingtong
Qingtong earned 400 total points
ID: 13972497
Cache is good thing to improve the performance of the web site.

Typically what I did for cache is:

Public Function LoadSettings() as string

    Dim strCacheKey As String = TSG_DataGridController.TSG_SETTINGS & "_" & ModuleId

    If Cache.Item(strCacheKey) Is Nothing Then
         Dim strSetting As String = String.Empty
         strSetting = 'get setting string somewhere or any datatype such as datatable, dataset or ....
         Cache.Insert(strCacheKey, strSetting, Nothing, DateTime.Now.AddSeconds(10), TimeSpan.Zero)
    End If

    return Ctype(Cache.Item(strCacheKey), string)
End Function

This cache will be expired in 10 seconds.

Acturally you may cache any data type. And if you have any dependency put it in Cache.Insert instead of Nothing.
Right now the dependency is only support file change, as I know. So if your data source is based on XML file, then put the file name here.
It cannot take any database change for SQL2000. It is said SQL2005 has the function for cache dependency

Hope it may help.

Qingtong
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 13978874
thx for the points

>>since the department collection doesn't change very often (if at all), i thought this would be a great candidate for caching.  depending on the department selected, the second drop down list box will list all the employees for that employee.  do you think I should create a cache object that will hold the employees for each department

Actually it all depends on the size of the data you r caching ... and also how frequently u use the data and how frequently it changes ... lets say u have a screen where u want to list all the employess and another screen (as u mentioned) where u list employees based on dept, then ur original idea of caching different cache for each type of employee would not be of any advantage for the first screen. ... in these type of scenarion .. u should hold dept in one cache and another cache having list of employees with the dept ids .. for the first screen u can directly get the list from the cache and for the second screen u can filter out the employees for the selected dept .... hope u got what i am trying to explain ..

in another scenario, u have a single screen which is rarely used by the user which list the employees, then it does not really make sense in caching the employee data .... u have to decide on what and how long to cache based on the frequency of usage ....
if the employee data is not
0
 
LVL 7

Author Comment

by:brdrok
ID: 13978924
i'm gonna have to "grok" this very carefully but I do believe I got the main idea out of it.  ever got the feeling that programming is more art than science <grin>

i really do apprciate you guys taking time out explaning stuff to me.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month18 days, 23 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question