Tuesday 31 January 2012

Provider for Memcache(VB.NET)


Imports Enyim.Caching
Imports Enyim.Caching.Memcached

Namespace CacheService
    Public Class MemcacheProvider
        Implements ICacheProvider

        Private Shared _instant As MemcachedClient
        Public Shared ReadOnly Property Instant() As MemcachedClient
            Get
                If _instant Is Nothing Then
                    _instant = New MemcachedClient()
                End If
                Return _instant
            End Get
        End Property

        Public Function [Get](ByVal key As String) As Object Implements ICacheProvider.[Get]
            Return Instant.[Get](key)
        End Function

        Public Sub Add(ByVal key As String, ByVal value As Object) Implements ICacheProvider.Add
            Instant.Store(StoreMode.Add, key, value)
        End Sub

        Public Sub Add(ByVal key As String, ByVal value As Object, ByVal timeout As Integer) Implements ICacheProvider.Add
            Instant.Store(StoreMode.Add, key, value, DateTime.Now.AddMinutes(timeout))
        End Sub

        Public Sub Update(ByVal key As String, ByVal value As Object) Implements ICacheProvider.Update
            Instant.Store(StoreMode.[Set], key, value)
        End Sub

        Public Sub UpdateWithTimeOut(ByVal key As String, ByVal value As Object, ByVal timeout As Integer) Implements ICacheProvider.Update
            Instant.Store(StoreMode.[Set], key, value, DateTime.Now.AddMinutes(timeout))
        End Sub

        Public Sub Remove(ByVal key As String) Implements ICacheProvider.Remove
            Instant.Remove(key)
        End Sub


    End Class
End Namespace

No comments:

Post a Comment