Skip to content

Instantly share code, notes, and snippets.

View sara4dev's full-sized avatar
🏠
Working from home

Saravana Periyasamy sara4dev

🏠
Working from home
  • nvidia
  • Dallas, TX
  • 15:12 (UTC -05:00)
  • X @sara4dev
View GitHub Profile
```
kubectl get po | grep Evicted | awk '{print $1}' | xargs kubectl delete po
```
@sara4dev
sara4dev / git-branch-author
Created May 8, 2014 23:25
git command to list all the branch with author details
git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n
<cache:annotation-driven cache-manager="cacheManager" key-generator="cacheKeyGenerator"/>
<bean id="cacheKeyGenerator" class="com.meygam.cache.CacheKeyGenerator"/>
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.cache.interceptor.KeyGenerator;
public class CacheKeyGenerator implements KeyGenerator {
@Override
public Object generate(Object o, Method method, Object... objects) {
HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
hashCodeBuilder.append(method.getName());
for (Object object : objects) {
hashCodeBuilder.append(object);
import org.springframework.cache.annotation.Cacheable;
.
.
@Cacheable("longCache")
public List<Product> getAllProducts(final int pageNumber) {
System.out.println("Inside DAO so cache did not get used");
// TODO Auto-generated method stub
Query query = getEntityManager().createQuery("SELECT p FROM Product p");
return query.setFirstResult(pageNumber * PAGE_SIZE)
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false" maxBytesLocalHeap="1g"
maxBytesLocalOffHeap="4g" maxBytesLocalDisk="100g" >
<defaultCache maxElementsInMemory="5" eternal="false"
timeToIdleSeconds="20" timeToLiveSeconds="20"
overflowToDisk="false" diskPersistent="false"
memoryStoreEvictionPolicy="LRU"/>
<cache name="longCache" timeToLiveSeconds="10000"/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehcache"/>
</bean>
<!-- Ehcache library setup -->
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
</bean>
@sara4dev
sara4dev / SpringCacheAnnotationConfig.xml
Last active December 23, 2015 09:19
Spring cache annotation configuration with default key generator
<cache:annotation-driven cache-manager="cacheManager"/>
@sara4dev
sara4dev / SpringCache.xml
Last active December 23, 2015 09:19
Cache namespace and schema in spring config file.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
</beans>
@sara4dev
sara4dev / EhcacheDependency.xml
Last active December 23, 2015 09:19
Maven entry for ehcache in pom.xml
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.3.1</version>
</dependency>