jesus4u Posted October 7, 2003 Posted October 7, 2003 I am trying to add an array list to a cache object in my WebService. But it only loads the first 2 attempts and ignores any other attempts to load data into the cache. Why? Imports System.Web.Services 'Imports System.Web.Caching.Cache <System.Web.Services.WebService(Namespace:="http://tempuri.org/wsTranscriptsTest/Service1")> _ Public Class HoldingTank Inherits System.Web.Services.WebService Dim strArray As New ArrayList #Region " Web Services Designer Generated Code " Public Sub New() MyBase.New() 'This call is required by the Web Services Designer. InitializeComponent() 'Add your own initialization code after the InitializeComponent() call End Sub 'Required by the Web Services Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Web Services Designer 'It can be modified using the Web Services Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 'CODEGEN: This procedure is required by the Web Services Designer 'Do not modify it using the code editor. If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub #End Region [color=green] <WebMethod()> _ Public Function HelloWorld() As ArrayList If Context.Cache("strArray") Is Nothing Then CreateCache() End If Dim arrReturnList As ArrayList = CType(Context.Cache("strArray"), ArrayList) Context.Cache.Remove("strArray") Return arrReturnList End Function <WebMethod()> _ Public Sub FillCache(ByVal strValue As String) If Context.Cache("strArray") Is Nothing Then CreateCache() End If strArray.Add(strValue) Context.Cache.Add("strArray", strArray, Nothing, Now.AddHours(1), Nothing, Caching.CacheItemPriority.High, Nothing) End Sub Private Sub CreateCache() strArray.Add("StarterValue") 'Context.Cache.Insert("strArray", strArray) Context.Cache.Add("strArray", strArray, Nothing, Now.AddHours(1), Nothing, Caching.CacheItemPriority.High, Nothing) End Sub End Class [/color] Quote Alex Polajenko
jesus4u Posted October 7, 2003 Author Posted October 7, 2003 I seemed to figure it out. Still don't CLEARLY understand why though ;) <WebMethod()> _ Public Function HelloWorld() As ArrayList If Context.Cache("strArray") Is Nothing Then CreateCache() End If Dim arrReturnList As ArrayList = CType(Context.Cache("strArray"), ArrayList) Context.Cache.Remove("strArray") Return arrReturnList End Function <WebMethod()> _ Public Sub FillCache(ByVal strValue As String) If Context.Cache("strArray") Is Nothing Then CreateCache() End If strArray = CType(Context.Cache("strArray"), ArrayList) strArray.Add(strValue) Context.Cache.Add("strArray", strArray, Nothing, Now.AddHours(1), Nothing, Caching.CacheItemPriority.High, Nothing) End Sub Private Sub CreateCache() strArray.Add("StarterValue") Context.Cache.Add("strArray", strArray, Nothing, Now.AddHours(1), Nothing, Caching.CacheItemPriority.High, Nothing) End Sub Quote Alex Polajenko
*Experts* Volte Posted October 7, 2003 *Experts* Posted October 7, 2003 If you have Option Strict on, then you need to cast objects to their correct types before using them. For example, Context.Cache("strArray")actually returns an Object, which you need to cast to ArrayList before it is usable. Quote
jesus4u Posted October 7, 2003 Author Posted October 7, 2003 I am not explicitly using Option Strict on so is it on by default then? Thanks Quote Alex Polajenko
*Experts* Volte Posted October 7, 2003 *Experts* Posted October 7, 2003 No, I don't think so... what happens when you don't have that line in there, specifically? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.