0

I read my data from cache . I am using ehcache. I need to refresh my cache data after every insert action. How i can do it with annotation ? or any other way ?

ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true"
monitoring="autodetect"
dynamicConfig="true">

 <diskStore path="java.io.tmpdir" />

 <defaultCache
    maxElementsInMemory="10000" 
    eternal="true"
    timeToIdleSeconds="120" 
    timeToLiveSeconds="120" 
    overflowToDisk="true"
    maxElementsOnDisk="10000000" 
    diskPersistent="true"
    diskExpiryThreadIntervalSeconds="120" 
    memoryStoreEvictionPolicy="LRU" />

<cache name="allNodesCache"
    maxEntriesLocalHeap="10000"
    maxEntriesLocalDisk="1000"
    eternal="false"
    diskSpoolBufferSizeMB="20"
    timeToIdleSeconds="300" timeToLiveSeconds="600"
    memoryStoreEvictionPolicy="LFU"
    transactionalMode="off">
    <persistence strategy="localTempSwap" />
</cache>

<cache name="nodesMAPCache"
    maxElementsInMemory="10000" 
    eternal="true"
    timeToIdleSeconds="120" 
    timeToLiveSeconds="120" 
    overflowToDisk="true"
    maxElementsOnDisk="10000000" 
    diskPersistent="true"
    diskExpiryThreadIntervalSeconds="120" 
    memoryStoreEvictionPolicy="LRU" />

<cache name="nodesCache"
    maxElementsInMemory="10000" 
    eternal="true"
    timeToIdleSeconds="120" 
    timeToLiveSeconds="120" 
    overflowToDisk="true"
    maxElementsOnDisk="10000000" 
    diskPersistent="true"
    diskExpiryThreadIntervalSeconds="120" 
    memoryStoreEvictionPolicy="LRU" />

Repository class:

Repository

public interface NodeRepository extends JpaRepository {

@Cacheable(value = "nodesCache")
@Query("select new com.datum.fnd.domain.Node(c.idNode, c.name, c.address, c.description, c.point) from Node c")
List<Node> selectAll();
1

1 Answer 1

1

I have solved my problem with following code:

@CacheEvict(cacheNames = { "nodesCache", "nodesMAPCache" }, allEntries = true)
@Override
public Node create(Node node) {
    node.setName(nodeRepository.generateNodeName(node.getRegion().getIdRegion()));
    return nodeRepository.save(node);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.