Velocity Cache Notifications
Velocity Cache Notifications
I’ve been asked by a friend how to
use cache notifications in Velocity.
if you don’t know, Velocity,
Microsoft distributed cache, offers a
cache notification mechanism that can
help you to get notified when cache operations occur.
This post will help you to get started with Velocity cache notifications.
Cache Notifications
As written earlier, Velocity has a cache notifications feature. That feature
enables us to get notified when cache operations occur in our cache cluster.
What happens when this feature is enabled is that we get asynchronous
cache notifications for many aspects of the cluster including the cache,
region and cached item operations.
The following are the notifications that we can receive:
- Create/Clear/Remove regions.
- Add/Replace/Remove cached items.
The following notifications can be added:
- Cache level callback – get notified on all the operations that
occur on all the items and regions in a specific cache.
- Region level callback – get notified on all the operation that
occur on all the items and region of a specific region.
- Item level callback – get notified on all the operations that
occur to a specific item.
For more details go to the following MSDN post – Cache Notifications (Velocity).
How to Enable Cache Notifications?
In order to enable server cache notifications (which is disabled by default)
we need to configure the relevant named cache. There are two
PowerShell commands that enables us to do that thing which are
New-Cache and Set-CacheConfig.
They get as parameter NotificationEnabled which enable the cache.
For example –
New-Cache –CacheName cache1 –NotificationsEnabled
will create a new named cache with the name cache1 which has the
cache notifications enabled.
Summary
Lets sum up, Velocity is going to be shipped with cache notification mechanism.
That mechanism can help you to get notified whenever a cache operation
occurs. This mechanism can help to monitor the Velocity cluster or to know
when operation occurs in the cache. In the post I showed how to enable
cache notifications in a specific named cache. In the next post I’ll demonstrate
how to add cache notifications callbacks.