[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Caching in Forms application

hcurrie

10/28/2008 11:56:00 AM

I am wanting to use caching in a Windows Forms app. The help for the Cache
class says:

"The Cache class is not intended for use outside of ASP.NET applications. It
was designed and tested for use in ASP.NET to provide caching for Web
applications. In other types of applications, such as console applications
or Windows Forms applications, ASP.NET caching might not work correctly."

I have created a very simple test application, and so far it seems to work
fine, except that the expiration seems to take a little longer than the time
I specify.
Has anyone else tried this, and found any problems?

Public Class Form1
Private onRemove As CacheItemRemovedCallback
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' set-up the delegate for the callback
onRemove = New CacheItemRemovedCallback(AddressOf RemovedCallback)
Debug.Print(Now)
HttpRuntime.Cache.Add("One", 1, Nothing, Cache.NoAbsoluteExpiration, New
TimeSpan(0, 0, 10), CacheItemPriority.Default, onRemove)
HttpRuntime.Cache.Add("Two", 2, Nothing, Cache.NoAbsoluteExpiration, New
TimeSpan(0, 0, 20), CacheItemPriority.Default, onRemove)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Debug.Print(Now)
MsgBox(HttpRuntime.Cache("One"))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Debug.Print(Now)
MsgBox(HttpRuntime.Cache("Two"))
End Sub
Public Sub RemovedCallback(ByVal Key As String, ByVal Value As Object, ByVal
Reason As CacheItemRemovedReason)
Debug.Print(Now)
MsgBox(Key & "(" & Value & ") removed from the cache")
End Sub
End Class


4 Answers

hcurrie

10/29/2008 9:19:00 AM

0

>I am wanting to use caching in a Windows Forms app. The help for the Cache
> class says:
>
> "The Cache class is not intended for use outside of ASP.NET applications.
> It
> was designed and tested for use in ASP.NET to provide caching for Web
> applications. In other types of applications, such as console applications
> or Windows Forms applications, ASP.NET caching might not work correctly."
>
> I have created a very simple test application, and so far it seems to work
> fine, except that the expiration seems to take a little longer than the
> time
> I specify.
> Has anyone else tried this, and found any problems?

I found a document called: Caching Architecture Guide for .NET Framework
Applications.
In here it states:
*Using the ASP.NET Cache in Non-Web Applications*
The ASP.NET cache object is located in the System.Web namespace, and because
it is a generic cache implementation, it can be used in any application that
references this namespace.

So I guess it's OK.


jialge

10/29/2008 9:29:00 AM

0

Hello Phil

According to the KB article: http://support.microsoft.com...

The System.Web.Caching.Cache object is not intended for use outside ASP.NET
in the .NET Framework 1.1 and in the .NET Framework 1.0, however, it can be
used in .NET 2.0 framework:

<quote>
Note The specific problem that is described in the "More Information"
section does not occur in the Microsoft .NET Framework 2.0. Therefore, you
can use the Cache object outside ASP.NET in the .NET Framework 2.0.
However, we recommend that you consider using the Caching Application Block
because it offers you more options for customization to meet application
requirements.
</quote>

Does this answer your concerns?

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#not....

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa9...
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

hcurrie

10/31/2008 10:54:00 AM

0

> According to the KB article: http://support.microsoft.com...
>
> The System.Web.Caching.Cache object is not intended for use outside
> ASP.NET
> in the .NET Framework 1.1 and in the .NET Framework 1.0, however, it can
> be
> used in .NET 2.0 framework:
>
> <quote>
> Note The specific problem that is described in the "More Information"
> section does not occur in the Microsoft .NET Framework 2.0. Therefore, you
> can use the Cache object outside ASP.NET in the .NET Framework 2.0.
> However, we recommend that you consider using the Caching Application
> Block
> because it offers you more options for customization to meet application
> requirements.
> </quote>
>
> Does this answer your concerns?
>
Yes it does thanks. I am using VS2008 and .Net Framework 3.5, so presumably
it will be OK.
I may take a look at the Caching Application Block, although at first glance
it looks a lot more complicated to set-up and configure.
Do you know if this supported in VS2008 Standard edition, and if it requires
SQL Server?

Thanks,
Phil.


jialge

11/3/2008 10:49:00 AM

0

Hello Phil.

> Do you know if this supported in VS2008 Standard edition?

It depends on the version of Enterprise Library. Both Enterprise Library
4.0 and 4.1 support Visual Studio 2008 Standard Edition. This information
is documented at:
http://msdn.microsoft.com/en-us/library/dd2...
http://msdn.microsoft.com/en-us/library/cc5...
(see the "System Requirement" section)

> Do you know if it requires SQL Server?

Caching Application Block supports both an in-memory cache and, optionally,
a backing store that can either be the database store or isolated storage.
The backing store would require SQL Server, but in-memory mode does not.

Have a nice day!

Best Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================