.NETGURU
Cache
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcache' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Gfw
I'm building a WebService to return partial pages. I'm trying to use the
Cache with little success. What namespace am I missing. Thanks for any
help.

======================================================
Error Message...
The name 'Cache' does not exist in the class or namespace 'yyyZWs.About'

Code...

protected static string strGfw;

[WebMethod]
public string Gfw()
{
     // Is it in the Cache
     strGfw = (string)Cache["GfwAbout"];
     // Found - return the Cache Copy
     if (strGfw!=null) return strGfw;
     // Not Found - Load, Place in Cache and return
     string HdLoc = Server.MapPath("Text")+ "\\" +"GfwAbout.Txt";

     try
     { StreamReader strm = new StreamReader(
File.OpenRead(HdLoc));
     strGfw = strm.ReadToEnd();
     strm.Close();
     Cache["GfwAbout"] = (string)strGfw;
     }
     catch
     {
     }
     return strGfw;
}
======================================================

Gfw
mailto:Click here to reveal e-mail address
http://yyyZ.net

Reply to this message...
 
    
Rob Howard (VIP)
Hi,

By default the Cache API is not available in a Web Service. To access
the Cache API:

using System.Web.Caching;
...
Cache cache =3D HttpContext.Current.Cache;

Thanks
Rob

-----Original Message-----
From: Gfw [mailto:Click here to reveal e-mail address]=20
Sent: Monday, March 04, 2002 6:22 AM
To: aspngcache
Subject: [aspngcache] Cache

I'm building a WebService to return partial pages. I'm trying to use the
Cache with little success. What namespace am I missing. Thanks for any
help.

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
Error Message...
The name 'Cache' does not exist in the class or namespace 'yyyZWs.About'

Code...

protected static string strGfw;

[WebMethod]
public string Gfw()
{=20
     // Is it in the Cache=20
     strGfw =3D (string)Cache["GfwAbout"];
     // Found - return the Cache Copy
     if (strGfw!=3Dnull) return strGfw;=20
     // Not Found - Load, Place in Cache and return=20
     string HdLoc =3D Server.MapPath("Text")+ "\\" +"GfwAbout.Txt";

     try
     { StreamReader strm =3D new StreamReader(
File.OpenRead(HdLoc)); =20
     strGfw =3D strm.ReadToEnd();
     strm.Close();
     Cache["GfwAbout"] =3D (string)strGfw;
     }
     catch
     {
     }
     return strGfw;
}
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D

Gfw
mailto:Click here to reveal e-mail address
http://yyyZ.net
=20

| [aspngcache] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.aspfriends.com/aspfriends/aspngcache.asp =3D JOIN/QUIT

Reply to this message...
 
    
Scott Mahler
-- Moved from [aspngfreeforall] to [aspngcache] by devin <Click here to reveal e-mail address> --

Hi all,

On a web app, I have been using me.cache("someVariable") to store
variables across page postbacks (instead of the hidden input boxes a la
classic asp)

I assumed (and wrongly, I'm learning) that the cache was for the page
only and for that session only
I Have come to discover that if two users on different boxes are
accessing the same page, then they are overwriting each others "Cache".

Can someone please inform me, how to make the "Cache" unique to the User
(or Session)

I could use Session Variables, or I could use hidden input boxes, but
I'd like to do it the "Best Practices way"

TIA

Scott

Reply to this message...
 
    
Scott Watermasysk (VIP)
The cache is not unique per user.

As long as you are only talking about persisting values during postbacks
(not across multiple pages) use ViewState. You can access ViewState in the
main manor as session. The disadvantage to ViewState is that it gets written
back to the client broswer in a hidden tag. This mean is could be
potentially decoded and it also increases the amount of data sent back to
the client.

Session is unique per user, but it does take up some of your system's
memory. In addition, you will run into other problems if you are working in
a cluster. The advantage her is that Session is persisted from page to page.

You also have the HttpContext which allows you to store information for the
current request. This is good if you have a couple controls sharing the same
piece of information...but this will not be persisted page to page or even
on postbacks.

HTH,
Scott

-----Original Message-----
From: Scott Mahler [mailto:Click here to reveal e-mail address]
Sent: Tuesday, May 14, 2002 2:42 PM
To: aspngcache
Subject: [aspngcache] Cache

-- Moved from [aspngfreeforall] to [aspngcache] by devin
<Click here to reveal e-mail address> --

Hi all,

On a web app, I have been using me.cache("someVariable") to store variables
across page postbacks (instead of the hidden input boxes a la classic asp)

I assumed (and wrongly, I'm learning) that the cache was for the page only
and for that session only I Have come to discover that if two users on
different boxes are accessing the same page, then they are overwriting each
others "Cache".

Can someone please inform me, how to make the "Cache" unique to the User (or
Session)

I could use Session Variables, or I could use hidden input boxes, but I'd
like to do it the "Best Practices way"

TIA

Scott
| [aspngcache] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngcache.asp = JOIN/QUIT

Reply to this message...
 
    
John Crim
When storing user-specific values, that are to be shared between pages,
use the Session object.

When storing page-specific values, use the ViewState object:

ViewState["ShowDetails"] = true;

The ViewState is implemented using an encrypted hidden field, so stored
ViewState is only present on postbacks of the same page. If the user
returns to a page via a link from another page, the ViewState will no
longer be there.

Stored Session state is present on all later page views for that user,
until the Session expires.

Regards,

John Crim
WebGecko Software
http://www.webgecko.com

-----Original Message-----
From: Scott Mahler [mailto:Click here to reveal e-mail address]
Sent: Tuesday, May 14, 2002 11:42 AM
To: aspngcache
Subject: [aspngcache] Cache

-- Moved from [aspngfreeforall] to [aspngcache] by devin
<Click here to reveal e-mail address> --

Hi all,

On a web app, I have been using me.cache("someVariable") to store
variables across page postbacks (instead of the hidden input boxes a la
classic asp)

I assumed (and wrongly, I'm learning) that the cache was for the page
only and for that session only I Have come to discover that if two users
on different boxes are accessing the same page, then they are
overwriting each others "Cache".

Can someone please inform me, how to make the "Cache" unique to the User
(or Session)

I could use Session Variables, or I could use hidden input boxes, but
I'd like to do it the "Best Practices way"

TIA

Scott
| [aspngcache] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngcache.asp = JOIN/QUIT

Reply to this message...
 
    
Ahmed, Salman
I'm sure this has been asked before:

How can I clear all caches?
How can I clear caches at a page level while leaving other pages alone?

If there is a tutorial or link on this that would be great!

Reply to this message...
 
 
System.IO.File
System.IO.StreamReader
System.Messaging.Message
System.Web.HttpContext
System.Web.Services.WebService




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification