package com.xingxi.api.service.impl;

import com.google.common.cache.Cache;
import com.xingxi.api.service.CacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Slf4j
@Service
class GuavaCacheServiceImpl implements CacheService {
    private final Cache<String, Object> cache;

    GuavaCacheServiceImpl(@Qualifier("WxaMediaCheckGuavaCache") final Cache<String, Object> cache) {
        this.cache = cache;
    }


    @Override
    public void setCache(String key, Object value) {
        cache.put(key, value);

    }

    @Override
    public Object getCache(String key) {
        return cache.getIfPresent(key);
    }

    @Override
    public void invalidate(String key) {
        cache.invalidate(key);
    }
}
