Настройки для настройки региона сервера с настройками TTL. Я подожду некоторое время, прежде чем опубликовать его в качестве ответа. Был бы очень рад, если бы я узнал любой способ достижения того же с использованием API (ов).

жно ли иметьClientCache с участиемClientRegionShortcut.PROXY наряду с программным управлением настройками TTL записи (т. е. записи, присутствующие на сервере)?

Я вижу, что настройки ttl истечения срока действия записи работают нормальноClientRegionShortcut.CACHING_PROXY_HEAP_LRU, В этом случае я вижу, что записи становятся недействительными на сервере после заданного времени ожидания в секундах, но это не так дляClientRegionShortcut.PROXY настройки

ЭтоНЕ можно динамически управлять настройками entry-ttl дляClientCache?

Ниже код / ​​конфиг работает сClientRegionShortcut.CACHING_PROXY_HEAP_LRU а такжеНЕ с участиемClientRegionShortcut.PROXY.

Gemfire version is : 9.0.x pom выглядит как ниже

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

<groupId>com.springboot.gemfire</groupId>
<artifactId>app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>MyGemfireProject</name>
<description>Test Concepts project for Spring Boot with Gemfire</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-gemfire</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.modelmapper</groupId>
        <artifactId>modelmapper</artifactId>
        <version>0.7.4</version>
    </dependency>
    <dependency>
        <groupId>com.gemstone.gemfire</groupId>
        <artifactId>gemfire</artifactId>
        <version>8.2.6</version>
    </dependency>


</dependencies>

<repositories>
    <repository>
        <id>org.springframework.maven.milestone</id>
        <name>Spring Maven Milestone Repository</name>
        <url>http://repo.springsource.org/libs-milestone</url>
        <snapshots><enabled>false</enabled></snapshots>
    </repository>
</repositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Gemfire Конфигурация выглядит так:

import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.data.gemfire.ExpirationActionType;
import org.springframework.data.gemfire.support.GemfireCacheManager;

import com.gemstone.gemfire.cache.AttributesMutator;
import com.gemstone.gemfire.cache.ExpirationAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.client.ClientRegionFactory;
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
import com.gemstone.gemfire.pdx.ReflectionBasedAutoSerializer;

/**
 * The Class NativeGemfireConfig.
 */
@Configuration
@Profile("local")
public class NativeGemfireConfig {

    /** The Constant log. */
    private static final Logger log = LoggerFactory.getLogger(NativeGemfireConfig.class);
    protected static final String DEFAULT_MANAGER_PORT = "1099";

    /** The region name. */
    @Value("${spring.gemfire.region.name:test}")
    private String regionName;

    @Bean
    Properties gemfireProperties(@Value("${spring.gemfire.log-level}") String logLevel,
            @Value("${spring.gemfire.mcast-port}") String mcastPort,
            @Value("${spring.gemfire.jmx-manager}") String jmxManager,
            @Value("${spring.gemfire.jmx-manager-start}") String jmxManagerStart,
            @Value("${spring.gemfire.username}") String gemfireuser,
            @Value("${spring.gemfire.password}") String gemfirepassword) {

        Properties gemfireProperties = new Properties();

        gemfireProperties.setProperty("name", NativeGemfireConfig.class.getSimpleName());
        gemfireProperties.setProperty("mcast-port", mcastPort);
        gemfireProperties.setProperty("log-level", logLevel);
        gemfireProperties.setProperty("jmx-manager", jmxManager);
        gemfireProperties.setProperty("jmx-manager-port", DEFAULT_MANAGER_PORT);
        gemfireProperties.setProperty("jmx-manager-start", jmxManagerStart);
        gemfireProperties.setProperty("security-username", gemfireuser);
        gemfireProperties.setProperty("security-password", gemfirepassword);
        gemfireProperties.setProperty("security-client-auth-init",
                "com.springboot.gemfire.config.GemFireAuthInitializor.create");

        return gemfireProperties;
    }

    @Bean
    @Primary
    ReflectionBasedAutoSerializer reflectionBasedAutoSerializer() {
        return new ReflectionBasedAutoSerializer("com.springboot.gemfire.model.*");
    }

    @Bean
    @Primary
    ClientCacheFactory clientCacheFactory(@Value("${spring.gemfire.host}") String gemFirehost,
            @Value("${spring.gemfire.port}") int gemfirePort, Properties gemfireProperties,
            ReflectionBasedAutoSerializer reflectionBasedAutoSerializer) {

        ClientCacheFactory cachefactory = new ClientCacheFactory(gemfireProperties);
        cachefactory.addPoolLocator(gemFirehost, gemfirePort);
        cachefactory.setPdxSerializer(reflectionBasedAutoSerializer);
        cachefactory.setPdxReadSerialized(false);
        cachefactory.setPdxIgnoreUnreadFields(true);

        return cachefactory;
    }

    /**
     * Gemfire cache.
     *
     * @return the client cache
     */
     @Bean
     @Primary 
     ClientCache gemfireCache(@Qualifier("gemfireProperties")Properties gemfireProperties, 
             ClientCacheFactory clientCacheFactory, 
             @Value("${spring.gemfire.username}") String gemfireuser,
             @Value("${spring.gemfire.password}") String gemfirepassword) 
     {

     return 
             clientCacheFactory
                 .set("security-username", gemfireuser)
                 .set("security-password", gemfirepassword)
                 .set("security-client-auth-init", 
                         "com.springboot.gemfire.config.GemFireAuthInitializor.create")
                 .create(); 
     }


    @Bean
    public ExpirationAttributes entryTtlExpirationAttributes(
            @Value("${spring.gemfire.region.expiration.entry.ttl.timeout}") int timeout) {

        return new ExpirationAttributes(timeout,
                ExpirationActionType.INVALIDATE.getExpirationAction());
    }

    @Bean
    @Primary
    Region<Object, Object> tokenRegionBean(ClientCache gemfireCache,
            @Qualifier("entryTtlExpirationAttributes") ExpirationAttributes expirationAttributes) {

        ClientRegionFactory<Object, Object> tokenRegionFactory = gemfireCache
                .createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU);
        tokenRegionFactory.setStatisticsEnabled(true);

        Region<Object, Object> region = tokenRegionFactory.create(regionName);

        AttributesMutator<Object, Object> mutator = region.getAttributesMutator();
        mutator.setEntryTimeToLive(expirationAttributes);

        return region;
    }


    @Bean
    GemfireCacheManager cacheManager(ClientCache gemfireCache) {
        GemfireCacheManager cacheManager = new GemfireCacheManager();
        cacheManager.setCache(gemfireCache);

        return cacheManager;
    }


    /**
     * Gets the region name.
     *
     * @return the region name
     */
    public String getRegionName() {
        return regionName;
    }

    /**
     * Sets the region name.
     *
     * @param regionName
     *            the new region name
     */
    public void setRegionName(final String regionName) {
        this.regionName = regionName;
    }
}

application-local.yml соответствующие записи

spring:
  gemfire:
    log-level: config
    region: 
      name: myRegion
      expiration:
        entry:
          ttl:
            timeout: 120
    host: remote-server
    port: port-to-connect
    mcast-port: 0
    jmx-manager: false
    jmx-manager-start: false
    username: uname
    password: passwd

Ответы на вопрос(0)

Ваш ответ на вопрос