Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 180 lines (157 sloc) 6.144 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Net;
using System.Web.Configuration;
using Enyim.Caching.Memcached;
using Enyim.Reflection;

namespace Enyim.Caching.Configuration
{
/// <summary>
/// Configures the <see cref="T:MemcachedClient"/>. This class cannot be inherited.
/// </summary>
public sealed class MemcachedClientSection : ConfigurationSection, IMemcachedClientConfiguration
{
/// <summary>
/// Returns a collection of Memcached servers which can be used by the client.
/// </summary>
[ConfigurationProperty("servers", IsRequired = true)]
public EndPointElementCollection Servers
{
get { return (EndPointElementCollection)base["servers"]; }
}

/// <summary>
/// Gets or sets the configuration of the socket pool.
/// </summary>
[ConfigurationProperty("socketPool", IsRequired = false)]
public SocketPoolElement SocketPool
{
get { return (SocketPoolElement)base["socketPool"]; }
set { base["socketPool"] = value; }
}

/// <summary>
/// Gets or sets the configuration of the authenticator.
/// </summary>
[ConfigurationProperty("authentication", IsRequired = false)]
public AuthenticationElement Authentication
{
get { return (AuthenticationElement)base["authentication"]; }
set { base["authentication"] = value; }
}

/// <summary>
/// Gets or sets the <see cref="T:Enyim.Caching.Memcached.IMemcachedNodeLocator"/> which will be used to assign items to Memcached nodes.
/// </summary>
[ConfigurationProperty("locator", IsRequired = false)]
public ProviderElement<IMemcachedNodeLocator> NodeLocator
{
get { return (ProviderElement<IMemcachedNodeLocator>)base["locator"]; }
set { base["locator"] = value; }
}

/// <summary>
/// Gets or sets the <see cref="T:Enyim.Caching.Memcached.IMemcachedKeyTransformer"/> which will be used to convert item keys for Memcached.
/// </summary>
[ConfigurationProperty("keyTransformer", IsRequired = false)]
public ProviderElement<IMemcachedKeyTransformer> KeyTransformer
{
get { return (ProviderElement<IMemcachedKeyTransformer>)base["keyTransformer"]; }
set { base["keyTransformer"] = value; }
}

/// <summary>
/// Gets or sets the <see cref="T:Enyim.Caching.Memcached.ITranscoder"/> which will be used serialzie or deserialize items.
/// </summary>
[ConfigurationProperty("transcoder", IsRequired = false)]
public ProviderElement<ITranscoder> Transcoder
{
get { return (ProviderElement<ITranscoder>)base["transcoder"]; }
set { base["transcoder"] = value; }
}

/// <summary>
/// Gets or sets the <see cref="T:Enyim.Caching.Memcached.IPerformanceMonitor"/> which will be used monitor the performance of the client.
/// </summary>
[ConfigurationProperty("performanceMonitor", IsRequired = false)]
public ProviderElement<IPerformanceMonitor> PerformanceMonitor
{
get { return (ProviderElement<IPerformanceMonitor>)base["performanceMonitor"]; }
set { base["performanceMonitor"] = value; }
}

/// <summary>
/// Called after deserialization.
/// </summary>
protected override void PostDeserialize()
{
WebContext hostingContext = base.EvaluationContext.HostingContext as WebContext;

if (hostingContext != null && hostingContext.ApplicationLevel == WebApplicationLevel.BelowApplication)
{
throw new InvalidOperationException("The " + this.SectionInformation.SectionName + " section cannot be defined below the application level.");
}
}

/// <summary>
/// Gets or sets the type of the communication between client and server.
/// </summary>
[ConfigurationProperty("protocol", IsRequired = false, DefaultValue = MemcachedProtocol.Binary)]
public MemcachedProtocol Protocol
{
get { return (MemcachedProtocol)base["protocol"]; }
set { base["protocol"] = value; }
}

#region [ IMemcachedClientConfiguration]

IList<IPEndPoint> IMemcachedClientConfiguration.Servers
{
get { return this.Servers.ToIPEndPointCollection(); }
}

ISocketPoolConfiguration IMemcachedClientConfiguration.SocketPool
{
get { return this.SocketPool; }
}

IMemcachedKeyTransformer IMemcachedClientConfiguration.CreateKeyTransformer()
{
return this.KeyTransformer.CreateInstance() ?? new DefaultKeyTransformer();
}

IMemcachedNodeLocator IMemcachedClientConfiguration.CreateNodeLocator()
{
return this.NodeLocator.CreateInstance() ?? new DefaultNodeLocator();
}

ITranscoder IMemcachedClientConfiguration.CreateTranscoder()
{
return this.Transcoder.CreateInstance() ?? new DefaultTranscoder();
}

IAuthenticationConfiguration IMemcachedClientConfiguration.Authentication
{
get { return this.Authentication; }
}

IServerPool IMemcachedClientConfiguration.CreatePool()
{
switch (this.Protocol)
{
case MemcachedProtocol.Text: return new DefaultServerPool(this, new Memcached.Protocol.Text.TextOperationFactory());
case MemcachedProtocol.Binary: return new Enyim.Caching.Memcached.Protocol.Binary.BinaryPool(this);
}

throw new ArgumentOutOfRangeException("Unknown protocol: " + (int)this.Protocol);
}

IPerformanceMonitor IMemcachedClientConfiguration.CreatePerformanceMonitor()
{
return this.PerformanceMonitor.CreateInstance();
}

#endregion
}
}

#region [ License information ]
/* ************************************************************
*
* Copyright (c) 2010 Attila Kiskó, enyim.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ************************************************************/
#endregion
Something went wrong with that request. Please try again.