category/getCategoryTree 加上二级缓存
This commit is contained in:
parent
11829cfc75
commit
8da1f87d46
|
@ -11,6 +11,8 @@ import io.renren.modules.category.service.CategoryService;
|
|||
import io.renren.modules.resource.dao.AttrDao;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -28,6 +30,8 @@ public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category,
|
|||
private static Integer cpuNUm = Runtime.getRuntime().availableProcessors();
|
||||
private static final ExecutorService executor = Executors.newFixedThreadPool(cpuNUm);
|
||||
|
||||
private static final String getCategoryTreeKey = "getCategoryTree";
|
||||
|
||||
@Autowired
|
||||
private CategoryDao categoryDao;
|
||||
@Autowired
|
||||
|
@ -39,6 +43,7 @@ public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category,
|
|||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = getCategoryTreeKey, key = "'getCategoryTree'")
|
||||
public List<CategoryDTO> getCategoryTree() {
|
||||
List<Category> topCategory = categoryDao.selectByParentId(null);
|
||||
List<CategoryDTO> list = new CopyOnWriteArrayList<>();
|
||||
|
@ -82,6 +87,7 @@ public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category,
|
|||
|
||||
@Override
|
||||
@Transactional
|
||||
@CacheEvict(key = getCategoryTreeKey, allEntries = true)
|
||||
public void deleteByIds(JSONObject jsonObject) {
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("ids");
|
||||
//TODO:删除为一级分类时,删除模板保存的文件夹?
|
||||
|
@ -125,6 +131,7 @@ public class CategoryServiceImpl extends CrudServiceImpl<CategoryDao, Category,
|
|||
|
||||
@Override
|
||||
@Transactional
|
||||
@CacheEvict(key = getCategoryTreeKey, allEntries = true)
|
||||
public void update(CategoryDTO categoryDTO) {
|
||||
super.update(categoryDTO);
|
||||
String oldName = categoryDao.selectById(categoryDTO.getId()).getName();
|
||||
|
|
|
@ -66,4 +66,13 @@
|
|||
overflowToDisk="true"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
<!-- getCategoryTree缓存 -->
|
||||
<cache name="getCategoryTree"
|
||||
maxElementsInMemory="10000"
|
||||
eternal="false"
|
||||
timeToIdleSeconds="60"
|
||||
timeToLiveSeconds="600"
|
||||
overflowToDisk="true"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
</ehcache>
|
Loading…
Reference in New Issue