新版仿ok交易所-后端
zyy
2025-09-03 a1c2c8df8c2741fdb4e1d30b1dd70e57133e1cb7
trading-order-service/src/main/java/com/yami/trading/service/item/ItemService.java
@@ -24,6 +24,7 @@
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -181,6 +182,23 @@
        return super.removeById(id);
    }
    // 清除 list() 方法的缓存(关键:与@Cached的name和key一致)
    /*@CacheEvict(cacheNames = ITEM_CACHE, key = "'all'")
    public void clearListCache() {
        log.info("已清除 list() 方法的缓存");
    }*/
    public void reloadListAndCache() {
        // 步骤1:清除 list() 方法的原有缓存(确保重新查询)
        //clearListCache();
        // 步骤2:重新调用 list() 方法,此时会执行数据库查询,且@Cached会自动更新缓存
        //List<Item> freshList = list();
        // 步骤3(可选):如果需要同步更新 init() 方法中的 itemCache,重新调用 init()
        init();
        log.info("初始化init()");
    }
    /**
     * 获取品种精度