All Projects → alibaba → Jetcache

alibaba / Jetcache

Licence: apache-2.0
JetCache is a Java cache framework.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Jetcache

Spring Boot
spring-boot 项目实践总结
Stars: ✭ 989 (-68.77%)
Mutual labels:  redis, cache, spring
Redisson
Redisson - Redis Java client with features of In-Memory Data Grid. Over 50 Redis based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Publish / Subscribe, Bloom filter, Spring Cache, Tomcat, Scheduler, JCache API, Hibernate, MyBatis, RPC, local cache ...
Stars: ✭ 17,972 (+467.48%)
Mutual labels:  redis, cache, spring-cache
Milkomeda
Spring extend componets which build from experience of bussiness, let developers to develop with Spring Boot as fast as possible.(基于Spring生态打造的一系列来自业务上的快速开发模块集合。)
Stars: ✭ 117 (-96.31%)
Mutual labels:  redis, cache, spring
Ssm booksystem
ssm demo,ssm详细教程,SSM简明教程:简单的十步教你搭建人生第一个SSM框架[ SSM框架整合教程(spring+spring mvc+mybatis+redis+maven+idea+bootstrap) ]
Stars: ✭ 355 (-88.79%)
Mutual labels:  redis, cache, spring
Study
全栈工程师学习笔记;Spring登录、shiro登录、CAS单点登录和Spring boot oauth2单点登录;Spring data cache 缓存,支持Redis和EHcahce; web安全,常见web安全漏洞以及解决思路;常规组件,比如redis、mq等;quartz定时任务,支持持久化数据库,动态维护启动暂停关闭;docker基本用法,常用image镜像使用,Docker-MySQL、docker-Postgres、Docker-nginx、Docker-nexus、Docker-Redis、Docker-RabbitMQ、Docker-zookeeper、Docker-es、Docker-zipkin、Docker-ELK等;mybatis实践、spring实践、spring boot实践等常用集成;基于redis的分布式锁;基于shared-jdbc的分库分表,支持原生jdbc和Spring Boot Mybatis
Stars: ✭ 159 (-94.98%)
Mutual labels:  redis, cache, spring
Spring Examples
Spring Examples
Stars: ✭ 172 (-94.57%)
Mutual labels:  redis, spring
Ansible Role Redis
Ansible Role - Redis
Stars: ✭ 176 (-94.44%)
Mutual labels:  redis, cache
Phpfastcache
A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
Stars: ✭ 2,171 (-31.45%)
Mutual labels:  redis, cache
Javacollection
Java开源项目之「自学编程之路」:学习指南+面试指南+资源分享+技术文章
Stars: ✭ 2,957 (-6.63%)
Mutual labels:  redis, spring
Cachemanager
CacheManager is an open source caching abstraction layer for .NET written in C#. It supports various cache providers and implements many advanced features.
Stars: ✭ 2,049 (-35.3%)
Mutual labels:  redis, cache
Interviewguide
《大厂面试指北》——包括Java基础、JVM、数据库、mysql、redis、计算机网络、算法、数据结构、操作系统、设计模式、系统设计、框架原理。最佳阅读地址:http://notfound9.github.io/interviewGuide/
Stars: ✭ 3,117 (-1.58%)
Mutual labels:  redis, spring
Redis Cache
A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Credis, HHVM, replication and clustering.
Stars: ✭ 205 (-93.53%)
Mutual labels:  redis, cache
Nginx Helper
Nginx Helper for WordPress caching, permalinks & efficient file handling in multisite
Stars: ✭ 170 (-94.63%)
Mutual labels:  redis, cache
Source Code Hunter
😱 从源码层面,剖析挖掘互联网行业主流技术的底层实现原理,为广大开发者 “提升技术深度” 提供便利。目前开放 Spring 全家桶,Mybatis、Netty、Dubbo 框架,及 Redis、Tomcat 中间件等
Stars: ✭ 7,392 (+133.41%)
Mutual labels:  redis, spring
Xbin Store
模仿国内知名B2C网站,实现的一个分布式B2C商城 使用Spring Boot 自动配置 Dubbox / MVC / MyBatis / Druid / Solr / Redis 等。使用Spring Cloud版本请查看
Stars: ✭ 2,140 (-32.43%)
Mutual labels:  redis, spring
Springbootlearning
《Spring Boot教程》源码
Stars: ✭ 2,065 (-34.8%)
Mutual labels:  redis, cache
Springboot mybatisplus
SpringBoot集成MyBatisPlus
Stars: ✭ 199 (-93.72%)
Mutual labels:  redis, spring
Pottery
Redis for humans. 🌎🌍🌏
Stars: ✭ 204 (-93.56%)
Mutual labels:  redis, cache
Cachingframework.redis
Distributed caching based on StackExchange.Redis and Redis. Includes support for tagging and is cluster-compatible.
Stars: ✭ 209 (-93.4%)
Mutual labels:  redis, cache
Springboot Examples
spring boot 实践系列
Stars: ✭ 216 (-93.18%)
Mutual labels:  redis, cache

Build Status Coverage Status GitHub release License

Introduction

JetCache is a Java cache abstraction which provides consistent use for various caching solutions. It provides more powerful annotation than that in Spring Cache. The annotation in JetCache supports native TTL, two level caching, and distributed automatically refreshment, also you can operate Cache instance by hand code. Presently There are four implements: RedisCache, TairCache(not open source on github), CaffeineCache (in memory), a simple LinkedHashMapCache (in memory). Full features of JetCache:

  • Operate cache through consistent Cache API.
  • Declarative method caching using annotation with TTL(Time To Live) and two level caching support
  • Create & configure Cache instance using annotation
  • Automatically collect access statistics for Cache instance and method cache
  • The policy of key generation and value serialization can be customized
  • Distributed cache automatically refreshment and distributed lock. (2.2+)
  • Asynchronous access using Cache API (2.2+, with redis lettuce client)
  • Spring Boot support

requirements:

  • JDK1.8
  • Spring Framework4.0.8+ (optional, with annotation support)
  • Spring Boot1.1.9+ (optional)

Visit wiki for more documents.

Getting started

Method cache

Declare method cache using @Cached annotation.
expire = 3600 indicates that the elements will expires in 3600 seconds after put. JetCache auto generates cache key using all parameters.

public interface UserService {
    @Cached(expire = 3600, cacheType = CacheType.REMOTE)
    User getUserById(long userId);
}

Using key attribute to specify cache key using SpEL script.

public interface UserService {
    @Cached(name="userCache-", key="#userId", expire = 3600)
    User getUserById(long userId);

    @CacheUpdate(name="userCache-", key="#user.userId", value="#user")
    void updateUser(User user);

    @CacheInvalidate(name="userCache-", key="#userId")
    void deleteUser(long userId);
}

To enable use parameter name such as key="#userId", you javac compiler target must be 1.8 and the -parameters should be set, otherwise use index to access parameters like key="args[0]"

Automatically refreshment:

public interface SummaryService{
    @Cached(expire = 3600, cacheType = CacheType.REMOTE)
    @CacheRefresh(refresh = 1800, stopRefreshAfterLastAccess = 3600, timeUnit = TimeUnit.SECONDS)
    @CachePenetrationProtect
    BigDecimal summaryOfToday(long categoryId);
}

CachePenetrationProtect annotation indicates to synchronize load operation in multi-thread environment.

Cache API

Create a Cache instance using @CreateCache annotation:

@CreateCache(expire = 100, cacheType = CacheType.BOTH, localLimit = 50)
private Cache<Long, UserDO> userCache;

The code above create a Cache instance. cacheType = CacheType.BOTH define a two level cache (a local in-memory-cache and a remote cache system) with local elements limited upper to 50(LRU based evict). You can use it like a map:

UserDO user = userCache.get(12345L);
userCache.put(12345L, loadUserFromDataBase(12345L));
userCache.remove(12345L);

userCache.computeIfAbsent(1234567L, (key) -> loadUserFromDataBase(1234567L));

Or you can create Cache instance manually (RedisCache in this example) :

GenericObjectPoolConfig pc = new GenericObjectPoolConfig();
pc.setMinIdle(2);
pc.setMaxIdle(10);
pc.setMaxTotal(10);
JedisPool pool = new JedisPool(pc, "localhost", 6379);
Cache<Long, UserDO> userCache = RedisCacheBuilder.createRedisCacheBuilder()
                .keyConvertor(FastjsonKeyConvertor.INSTANCE)
                .valueEncoder(JavaValueEncoder.INSTANCE)
                .valueDecoder(JavaValueDecoder.INSTANCE)
                .jedisPool(pool)
                .keyPrefix("userCache-")
                .expireAfterWrite(200, TimeUnit.SECONDS)
                .buildCache();

Advanced API

Asynchronous API:

CacheGetResult r = cache.GET(userId);
CompletionStage<ResultData> future = r.future();
future.thenRun(() -> {
    if(r.isSuccess()){
        System.out.println(r.getValue());
    }
});

Distributed lock:

cache.tryLockAndRun("key", 60, TimeUnit.SECONDS, () -> heavyDatabaseOperation());

Read through and automatically refreshment:

@CreateCache
@CacheRefresh(timeUnit = TimeUnit.MINUTES, refresh = 60, stopRefreshAfterLastAccess = 100)
@CachePenetrationProtect
private Cache<String, Long> orderSumCache;

@PostConstruct
public void init(){
    orderSumCache.config().setLoader(this::loadOrderSumFromDatabase);
}

Configuration with Spring Boot

pom:

<dependency>
    <groupId>com.alicp.jetcache</groupId>
    <artifactId>jetcache-starter-redis</artifactId>
    <version>${jetcache.latest.version}</version>
</dependency>

App class:

@SpringBootApplication
@EnableMethodCache(basePackages = "com.company.mypackage")
@EnableCreateCacheAnnotation
public class MySpringBootApp {
    public static void main(String[] args) {
        SpringApplication.run(MySpringBootApp.class);
    }
}

spring boot application.yml config:

jetcache:
  statIntervalMinutes: 15
  areaInCacheName: false
  local:
    default:
      type: linkedhashmap
      keyConvertor: fastjson
      limit: 100
  remote:
    default:
      type: redis
      keyConvertor: fastjson
      valueEncoder: java
      valueDecoder: java
      poolConfig:
        minIdle: 5
        maxIdle: 20
        maxTotal: 50
      host: ${redis.host}
      port: ${redis.port}

More docs

Visit wiki for more documents.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].