Adding to Cache Object NOT WORKING!
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?
Code:
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
<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