Skip to content

Commit

Permalink
Merge pull request #2 from HVG/dev-hvg
Browse files Browse the repository at this point in the history
Add: MemcachedClient support
  • Loading branch information
jeffrymorris committed Mar 9, 2015
2 parents d3b5eff + c54a003 commit 137e9fa
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions Couchbase.AspNet/CouchbaseClientFactory.cs
Expand Up @@ -3,28 +3,44 @@
using System.Configuration;
using Enyim.Caching;
using Couchbase.Configuration;
using Enyim.Caching.Configuration;

namespace Couchbase.AspNet
{
public sealed class CouchbaseClientFactory : ICouchbaseClientFactory
public sealed class CouchbaseClientFactory : ICouchbaseClientFactory
{
public IMemcachedClient Create(string name, NameValueCollection config, out bool disposeClient)
{
// This client should be disposed of as it is not shared
disposeClient = true;

// Get the section name from the configuration file. If not found, create a default Couchbase client which
// will get the configuration information from the default Couchbase client section in the Web.config file
var sectionName = ProviderHelper.GetAndRemove(config, "section", false);
if (String.IsNullOrEmpty(sectionName))
return new CouchbaseClient();
if (String.IsNullOrEmpty(sectionName))
return this.CreateClient(null);

// If a custom section name is passed in, get the section information and use it to construct the Couchbase client
var section = ConfigurationManager.GetSection(sectionName) as ICouchbaseClientConfiguration;
var section = ConfigurationManager.GetSection(sectionName);
if (section == null)
throw new InvalidOperationException("Invalid config section: " + section);
return new CouchbaseClient(section);
throw new InvalidOperationException("Invalid config section: " + sectionName);
return CreateClient(section);
}

private IMemcachedClient CreateClient(object config)
{
if (config != null && config.GetType() == typeof (ICouchbaseClientConfiguration))
{
return new CouchbaseClient(config as ICouchbaseClientConfiguration);
}

if (config != null && config.GetType() == typeof(IMemcachedClientConfiguration))
{
return new MemcachedClient(config as IMemcachedClientConfiguration);
}

return new CouchbaseClient();
}
}
}

Expand Down

0 comments on commit 137e9fa

Please sign in to comment.