Monday 27 June 2022

Ehcache: Get the current status of CacheManager

CacheManager#getStatus method return the current status of CacheManager.

 

Signature

Status getStatus()

 

There are three possible states.

a.   UNINITIALIZED: indicates it is not ready for use.

b.   MAINTENANCE: indicates exclusive access to allow for restricted operations.

c.    AVAILABLE: indicates it is ready for use.

 


 

Find the below working application.

 

CacheManagerState.java

 

package com.sample.app;

import org.ehcache.CacheManager;
import org.ehcache.config.builders.CacheManagerBuilder;

public class CacheManagerState {

	public static void main(String[] args) {
		CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(false);

		System.out.println("CacheManager status : " + cacheManager.getStatus());

		System.out.println("\nInitializing CacheManager");
		cacheManager.init();
		System.out.println("CacheManager status : " + cacheManager.getStatus());

		System.out.println("\nClosing CacheManager");
		cacheManager.close();
		System.out.println("CacheManager status : " + cacheManager.getStatus());
	}

}

 

Output

CacheManager status : UNINITIALIZED

Initializing CacheManager
CacheManager status : AVAILABLE

Closing CacheManager
CacheManager status : UNINITIALIZED

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment