Click here to Skip to main content
15,896,207 members
Articles / Programming Languages / XML

AppFabric Caching Extension

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
2 Jan 2012CPOL4 min read 42K   1.2K   17  
A component which can be plugged to a WCF service or any other client to utilize AppFabric caching features
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.ComponentModel;

namespace CachingExtension
{
    public class CacheOperationBehavior : Attribute, IOperationBehavior
    {
        double _minutesToCache;
        [Description("The number of minutes the response object will stay in the Cache")]
        public double MinutesToCache
        {
            get { return this._minutesToCache; }
            set { this._minutesToCache = value; }
        }

        //string _cacheName = string.Empty;

        #region IOperationBehavior Members

        public void AddBindingParameters(OperationDescription operationDescription,
            BindingParameterCollection bindingParameters)
        {
        }

        public void ApplyClientBehavior(OperationDescription operationDescription,
            ClientOperation clientOperation)
        {
        }

        public void ApplyDispatchBehavior(OperationDescription operationDescription,
            DispatchOperation dispatchOperation)
        {
           // TracingLibrary.TraceEvents.AddEvent("Inside Apply Dispatch Behavior");
            //Build the operation string using the namespace,   
           //service name and operation name   
            //ie: http://WCFService.com/myservice/myoperation  

           string operationFullName =   operationDescription.DeclaringContract.Namespace +  
                                                "/" + operationDescription.DeclaringContract.Name + "/" +   
                                                operationDescription.Name;

           // Replace the invoker with our own invoker
           dispatchOperation.Invoker = new CachingOperationInvoker(dispatchOperation.Invoker, this._minutesToCache, operationFullName);
        }

        public void Validate(OperationDescription operationDescription)
        {
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions