Code Monkey home page Code Monkey logo

javafamily-cache's Introduction

javafamily-cache

JavaFamily 缓存组件 SpringBoot Starter

Build MavenPublishSnapshot MavenPublishRelease

1. 引入依赖

  • Maven Central Release
<dependency>
   <groupId>club.javafamily</groupId>
   <artifactId>javafamily-cache</artifactId>
   <version>2.3.2-beta.2</version>
</dependency>
  • Maven Central Snapshot
   <!-- Snapshot 库需确保 snapshots 是被允许的 -->
   <repositories>
      <repository>
         <id>maven-central</id>
         <url>https://oss.sonatype.org/content/repositories/snapshots</url>
         <releases>
            <enabled>false</enabled>
            <updatePolicy>never</updatePolicy>
         </releases>
         <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
         </snapshots>
      </repository>
   </repositories>

   <dependencies>
      <dependency>
         <groupId>club.javafamily</groupId>
         <artifactId>javafamily-cache</artifactId>
         <version>2.3.2-SNAPSHOT</version>
      </dependency>
   </dependencies>

2. 配置

缓存组件底层目前提供 caffeineredis 两种实现方式, 默认为 caffeine 实现, 可支持配置包括:

属性 类型 描述 默认值
javafamily.cache.type CacheType Cache type. support caffeine/redis caffeine
javafamily.cache.cache-null-values java.lang.Boolean Allow caching null values. true
javafamily.cache.key-prefix java.lang.String Key prefix.
javafamily.cache.time-to-live java.time.Duration Entry expiration. By default the entries never expire.
javafamily.cache.use-key-prefix java.lang.Boolean Whether to use the key prefix when writing to cache. true
javafamily.cache.caffeine.spec java.lang.String The spec to use to create caches.
javafamily.cache.caffeine.initSize java.lang.Integer 初始化容量. 100
javafamily.cache.caffeine.maxSize java.lang.Long 最大容量. 2000
javafamily.cache.caffeine.weakKeys java.lang.Boolean key 是否启用软引用. false
javafamily.cache.caffeine.weakValues java.lang.Boolean value 是否启用软引用. false
javafamily.cache.caffeine.softValues java.lang.Boolean value 是否启用软引用. false
javafamily.cache.caffeine.recordStats java.lang.Boolean 是否启用状态记录. false

3. 使用

通过注入 CacheOperator 对象进行缓存操作.

@SpringBootTest
class CacheSimpleDemoApplicationTests {

    @Autowired
    private CacheOperator cacheOperator;

    @Test
    void testGetSet() {
        cacheOperator.setValue("key1", "v1");

        String v1 = cacheOperator.getValue("key1");

        Assertions.assertEquals(v1, "v1");
    }
}

4. 示例代码

javafamily-cache's People

Contributors

dreamli1314 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.