简体   繁体   English

memcache 不在多个节点上工作

[英]memcache is not working on multiple nodes

I am having one micro-service let's say 'X' in which i implemented Memcache (aws node) using spy-memcache.我有一个微服务,比如说“X”,我在其中使用 spy-memcache 实现了 Memcache(aws 节点)。 Now i have one dependency let's say 'Y' which is having spring cache (in memory) implementation.Now i have 2 end points sometimes both the end point requests lands on same node sometimes its on different.现在我有一个依赖项,比如说“Y”,它具有 spring 缓存(在内存中)实现。现在我有 2 个端点,有时两个端点请求都落在同一个节点上,有时它在不同的节点上。 1st request will put the data inside memcache and 2nd request will try to get the data stored by the first end point.This scenario is working fine until i put dependency 'Y' inside pom after that my implementation of memcache only works when both the request lands on same node otherwise its always a cache miss.第一个请求会将数据放入 memcache 中,第二个请求将尝试获取第一个端点存储的数据。这种情况工作正常,直到我将依赖项'Y'放入 pom 之后,我的 memcache 实现仅在两个请求时才有效落在同一个节点上,否则它总是缓存未命中。

I tried to create separate memcahe cache manager我试图创建单独的 memcahe 缓存管理器

@Bean("XYZ")
public CacheManager cacheManager() {
    ExtendedSSMCacheManager ssmCacheManager = new ExtendedSSMCacheManager();

    List<SSMCache> cacheList = new ArrayList<SSMCache>();

    // First cache: A
    SSMCache partnerCache = createNewCache(memcachedAddresses, "A", expiration);

    // One more  cache :B
    SSMCache nonceCache = createNewCache(memcachedAddresses, "B", expiration);

    cacheList.add(A);
    cacheList.add(B);

    // Adding cache list to cache manager
    ssmCacheManager.setCaches(cacheList);

    return ssmCacheManager;
}

Maybe you could try using memcached-spring-boot library instead of having your own cache configuration.也许您可以尝试使用memcached-spring-boot库而不是拥有自己的缓存配置。 It supports multiple memchached server instances.它支持多个 memchached 服务器实例。 Eg configuration if using AWS:例如,如果使用 AWS 的配置:

memcached.cache:
    servers: mycluster.example.com:11211
    mode: dynamic
    expirations: 86400

You could also check a demo app here which could help you setup your project in the similar way.你也可以在这里查看一个演示应用程序,它可以帮助你以类似的方式设置你的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM