【问题标题】:Memcached .Net client BufferedStream errorMemcached .Net 客户端 BufferedStream 错误
【发布时间】:2012-09-04 22:21:26
【问题描述】:

我正在尝试使用 Memcached.ClientLibrary。我能够使其正常工作,但在几次点击之后(甚至在我第一次看到页面之前),我收到了这个奇怪的错误,在搜索它时我找不到任何信息。

错误信息:

如果底层流不可查找,则在读取缓冲区不为空时无法写入 BufferedStream。确保此 BufferedStream 下的流可以在此 BufferedStream 上寻找或避免交错读取和写入操作。

堆栈跟踪:

[NotSupportedException: Cannot write to a BufferedStream while the read buffer is not empty if the underlying stream is not seekable. Ensure that the stream underlying this BufferedStream can seek or avoid interleaving read and write operations on this BufferedStream.]
System.IO.BufferedStream.ClearReadBufferBeforeWrite() +10447571
System.IO.BufferedStream.Write(Byte[] array, Int32 offset, Int32 count) +163
Memcached.ClientLibrary.SockIO.Write(Byte[] bytes, Int32 offset, Int32 count) in C:\devroot\memcacheddotnet\trunk\clientlib\src\clientlib\SockIO.cs:411
Memcached.ClientLibrary.SockIO.Write(Byte[] bytes) in C:\devroot\memcacheddotnet\trunk\clientlib\src\clientlib\SockIO.cs:391
Memcached.ClientLibrary.MemcachedClient.Set(String cmdname, String key, Object obj, DateTime expiry, Object hashCode, Boolean asString) in C:\devroot\memcacheddotnet\trunk\clientlib\src\clientlib\MemCachedClient.cs:766
Memcached.ClientLibrary.MemcachedClient.Set(String key, Object value, DateTime expiry) in C:\devroot\memcacheddotnet\trunk\clientlib\src\clientlib\MemCachedClient.cs:465
Yuusoft.Julian.Server.Models.Utils.Caching.CacheWrapper.Add(CacheKey key, T o, CacheDependency dependencies, Nullable`1 expirationTime, CacheItemRemovedCallback callBack)

我要初始化的代码(静态构造函数):

        SockIOPool pool = SockIOPool.GetInstance();
        pool.SetServers(CacheWrapper.Servers);

        pool.InitConnections = 3;
        pool.MinConnections = 1;
        pool.MaxConnections = 50;

        pool.SocketConnectTimeout = 1000;
        pool.SocketTimeout = 3000;

        pool.MaintenanceSleep = 30;
        pool.Failover = true;

        pool.Nagle = false;
        pool.Initialize();

// 要设置的代码(第二个是错误的 - 但不是在第一次命中?!)

        MemcachedClient mc = new MemcachedClient();
        mc.Set(key, o, expirationTime.Value);

//获取代码

        MemcachedClient mc = new MemcachedClient();
        object o = mc.Get(key);

【问题讨论】:

  • @DarthVader,发布了我的代码。你有什么想法?可以为我指明正确方向的东西?
  • @FabioMilheiro 如果此问题得到解决,请发布您的解决方案
  • @AbdulRaufMujahid,抱歉这是一个老实验,我最终没有完成。祝你好运
  • 就我而言,除了上述例外。我的 memcached 日志中也出现了以下 2 个异常(Error storing data in cache for key:Exception thrown while trying to get object from cache for key:),通过确保 memcached 键不包含任何空格,我能够解决所有这 3 个异常。
  • @AbdulRaufMujahid,感谢分享。如果您将其作为答案发布,我很乐意接受。

标签: c# c#-4.0 memcached


【解决方案1】:

除了这个异常之外,我的 Memcached.ClientLibrary 的 memcached log4net 日志中也存在以下两个异常(Error storing data in cache for key:<key with spaces>Exception thrown while trying to get object from cache for key:<key with spaces>)我能够解决所有这些 通过确保 memcached 键不包含任何空格来实现三个例外。

参考:https://groups.google.com/forum/#!topic/memcached/4WMcTbL8ZZY

Memcached 版本: memcached-win32-1.4.4-14

【讨论】:

    猜你喜欢
    • 2010-12-09
    • 1970-01-01
    • 2010-10-08
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 2010-10-18
    • 1970-01-01
    相关资源
    最近更新 更多