Skip to content

Instantly share code, notes, and snippets.

@teja463
Last active February 8, 2016 18:47
Show Gist options
  • Save teja463/93b2c221782b9caed70f to your computer and use it in GitHub Desktop.
Save teja463/93b2c221782b9caed70f to your computer and use it in GitHub Desktop.
package com.sample.service.service.impl;
import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
import com.liferay.portal.kernel.cache.PortalCache;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.Validator;
import com.sample.service.service.base.StudentServiceBaseImpl;
import java.io.Serializable;
public class StudentServiceImpl extends StudentServiceBaseImpl {
private static final Log _log = LogFactoryUtil.getLog(StudentServiceImpl.class);
public void testCache(String key,String value){
/** The below statement will return the cache with the name test
If the cache does not exists with the name cache it will create and return it. */
PortalCache<Serializable, Serializable> cache = MultiVMPoolUtil.getCache("test");
//Get the value from cache like below
Serializable serializable = cache.get(key);
/** Here i am checking if the passed key exists or not.
If does not exists I am putting it in the cache,
if it already exists i am getting the value from cache and returning it. */
if(Validator.isNull(serializable)){
cache.put(key, value);
_log.info("added into cache");
}else{
_log.info("found in the cache: "+cache.get(key));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment