0

Velocity はサーバー側のアトミック更新をサポートしていますか? memcache の INCR 操作に基づいてリング バッファを実装したコード (memcached に基づく) を移植できるかどうかを確認しようとしています。

4

1 に答える 1

3

memcachedに精通しているとは言えませんが、キャッシュされたアイテムをロックして、1つのクライアントが更新できるようにする必要があると想定しています。これは、GetAndLockとPutAndUnlockを介してVelocityでサポートされますメソッド。

編集:OK、今私はあなたが何を意味するのか理解しました、いいえ私はVelocityでそのようなものを見たことがありません。しかし、あなたはそれを拡張メソッドとして書くことができます例えば

Imports System.Runtime.CompilerServices

Public Module VelocityExtensions

<Extension()> _
Public Sub Increment(ByVal cache As Microsoft.Data.Caching.DataCache, ByVal itemKey As String)

    Dim cachedInteger As Integer
    Dim cacheLockHandle As DataCacheLockHandle

    cachedInteger = DirectCast(cache.GetAndLock(itemKey, New TimeSpan(0, 0, 5), cacheLockHandle), Integer)

    cachedInteger += 1

    cache.PutAndUnlock(itemKey, cachedInteger, cacheLockHandle)

End Sub

<Extension()> _
Public Sub Decrement(ByVal cache As Microsoft.Data.Caching.DataCache, ByVal itemKey As String)

    Dim cachedInteger As Integer
    Dim cacheLockHandle As DataCacheLockHandle

    cachedInteger = DirectCast(cache.GetAndLock(itemKey, New TimeSpan(0, 0, 5), cacheLockHandle), Integer)

    cachedInteger -= 1

    cache.PutAndUnlock(itemKey, cachedInteger, cacheLockHandle)

End Sub

End Module

その場合、使用法は次のようになります。

Imports VelocityExtensions
Imports Microsoft.Data.Caching

Partial Public Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim myCache As DataCache
    Dim factory As DataCacheFactory

    myCache = factory.GetCache("MyCacheName")

    myCache.Increment("MyInteger")

End Sub

End Class
于 2009-10-14T14:38:52.397 に答える