NamedCacheObjectExpired Event

ScaleOut Software NamedCache API
An event that is fired when an object cached within this NamedCache expires.

Namespace:  Soss.Client
Assembly:  soss_namedcache (in soss_namedcache.dll) Version:

public event NamedCacheObjectExpiredEventHandler ObjectExpired


Type: Soss.ClientNamedCacheObjectExpiredEventHandler

The event-handling feature must be enabled in the ScaleOut StateServer service in order for this event to fire. This feature is enabled by default -- the max_event_tries parameter in the soss_params.txt file (located in the StateServer installation directory) controls eventing in the StateServer service. See the "Configuration Parameters" topic in the SOSS Help file for details on the soss_params.txt file.

Note that in a server farm that is running multiple ScaleOut hosts, it is not possible to predict which host will receive the event. This allows ScaleOut StateServer to maximize performance by distributing events across the server farm. It is important to have the event-handling code running on each ScaleOut server to ensure that the expiration event is not lost. If the server farm is accessed solely by remote clients, there must be at least as many active remote clients as there are ScaleOut hosts; this ensures that all ScaleOut hosts can deliver events to a client. This requirement applies to all applications that perform event handling.

The CacheFactory creates one and only one NamedCache instance for any given application name. If you create a custom factory that creates NamedCache subclass instances, you could adopt a different policy. If there is more than one NamedCache instance for a given application name, you may establish an event handler on any instance and have it run if an ObjectExpired event is delivered to this client for the given application. In that case, the "sender" parameter of the NamedCacheObjectExpiredEventHandler callback will be set to the first NamedCache instance on which an event handler was registered.

Cached objects can be added to the cache with either an absolute or a sliding expiration scheme; retrieving or updating an object will reset the object's timeout if it uses a sliding expiration.


using System;
using Soss.Client;

class ExpirationSample
    static void Main(string[] args)
        // Get access to the named cache "Sample Cache"
        NamedCache cache = CacheFactory.GetCache("Sample Cache");
        // Register an event handler on the cache instance.
        cache.ObjectExpired += new NamedCache.ObjectExpiredEventHandler(NamedCache_ObjectExpired);

        // Create an object with a one minute lifetime:
        CreatePolicy cachePolicy = new CreatePolicy(1);
        cache.Insert("MyObjKey", "This is a cached object", cachePolicy, false, false);
        Console.WriteLine("The object was created.");

        // Wait for the object to expire so our program has a chance to receive the event.

    static void NamedCache_ObjectExpired(object sender, NamedCacheObjExpiredEventArgs eventArgs)
        // Examine the expiring object:
        NamedCache cache = CacheFactory.GetCache("Sample Cache");
        Console.WriteLine("An object with the following value has expired: " + cache[eventArgs.CachedObjectId]);

        // Choose between removing the object or allowing it to remain:
        eventArgs.NamedCacheObjDisposition = NamedCacheObjDisposition.Remove;
See Also