Spring Data GemFire:CustomExpiry示例 [英] Spring Data GemFire: CustomExpiry Examples

查看:112
本文介绍了Spring Data GemFire:CustomExpiry示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Pivotal GemFire 9.1.1和Spring Data GemFire 2.0.7.RELEASE.

I am using Pivotal GemFire 9.1.1 and Spring Data GemFire 2.0.7.RELEASE.

我有一个令牌,该令牌将使用String密钥和Map<String,String>值存储在GemFire区域中.令牌的有效期(即GemFire区域中的条目)应该是动态的,具体取决于一些业务场景.

I have a token that will be stored in a GemFire Region with a String Key and a Map<String,String> Value. The expiration of the token (i.e. entry in the GemFire Region) should be dynamic dependent on a few business scenarios.

我可以找到CustomExpiry的Pivotal GemFire文档,而我找不到关于Spring Data GemFire(<gfe:custom-entry-ttl>)的任何适当的示例/文档.

I could find Pivotal GemFire documentation for CustomExpiry whereas I could not find any proper example/documentation on Spring Data GemFire (<gfe:custom-entry-ttl>).

如果有资源指示如何在Spring Data GemFire中启用自定义数据过期,请共享.

Please share if there is a resource which instructs how to enable custom data expiration in Spring Data GemFire.

推荐答案

实际上,开发人员可以使用Pivotal GemFire的

There are actually 3 different ways a developer can configure a custom expiration policy for a Region using Pivotal GemFire's o.a.g.cache.CustomExpiry interface in SDG

给出o.a.g.cacheCustomExpiry ...

package example.app.gemfire.cache;

import org.apache.geode.cache.CustomExpiry;
import org.apache.geode.cache.ExpirationAttributes;
import ...;

class MyCustomExpiry implements CustomExpiry<String, Object> {

  ExpirationAttributes getExpiry(Region.Entry<String, Object> entry) {
    ...
  }
}

首先是XML方法.

<bean id="customTimeToLiveExpiration" 
      class="example.app.gemfire.cache.MyCustomExpiry"/>

<gfe:partitioned-region id="Example" persistent="false">
  <gfe:custom-entry-ttl ref="customTimeToLiveExpiration"/>
  <gfe:custom-entry-tti>
    <bean class="example.app.gemfire.cache.MyCustomExpiry"/>
  </gfe:custom-entry-tti>
</gfe:partitioned-region>

如您在上面的示例中看到的那样,您可以使用bean引用(如嵌套的生存时间(TTL)过期策略声明)或使用匿名bean定义来定义自定义"过期策略. 示例" PARTITION Region bean定义的嵌套空闲超时(TTI)过期策略中.

As you can see in the example above, you can define "custom" Expiration policies using either a bean reference, as in the nested Time-To-Live (TTL) Expiration Policy declaration or by using a anonymous bean definition, as in the nested Idle Timeout (TTI) Expiration Policy of the "Example" PARTITION Region bean definition.

有关精确定义,请参考SDG XML模式.

Refer to the SDG XML schema for precise definitions.

第二,您可以实现相同的Java Config ...

Second, you can achieve the same thing Java Config...

@Configuration
class GemFireConfiguration {

  @Bean
  MyCustomExpiry customTimeToLiveExpiration() {
    return new MyCustomExpiry();
  }

  @Bean("Example")
  PartitionedRegionFactoryBean<String, Object> exampleRegion(
      GemFireCache gemfireCache) {

    PartitionedRegionFactoryBean<String, Object> exampleRegion =
      new PartitionedRegionFactoryBean<>();

    exampleRegion.setCache(gemfireCache);
    exampleRegion.setClose(false);
    exampleRegion.setPersistent(false);
    exampleRegion.setCustomEntryTimeToLive(customTimeToLiveExpiration());
    exampleRegion.setCustomEntryIdleTimeout(new MyCustomExpiry());

    return exampleRegion;
  }
}

最后,您可以根据定义的

Finally, you configure both TTL and TTI Expiration Policies using SDG Annotation-based Expiration configuration, as defined here. There is a test class along with the configuration in the SDG test suite demonstrating this capability.

可以在希望这会有所帮助!

-约翰

这篇关于Spring Data GemFire:CustomExpiry示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆