Cache refreshing

Every cache implements interface of ICachedDao and can be refreshened.

ICachedDao refresh methods:

Refresh cache when expected record not found

When query not found expected result, you can refresh cache and try once again by implement function:

Refresh cache periodically

Daobab is integrated with Elephant Drummer Scheduler.
Implement CacheRefreshener, point classes to refresh, and add @DrummerJob to define scheduler

Example usage:

public  class PizzaRefreshener implements CacheRefreshener{

	private List<ICachedDataBaseDao<?>> target=new LinkedList<>();
	
	private @Inject IDaoPizza daoPizza;
	
	@DrummerJob(every=@Every(minute=1))
	public void job() {
		refreshAction();
	}
	
	@Override
	public List<ICachedDataBaseDao<?>> getTarget() {
		if (target.isEmpty()) {
			target.add(daoPizza);
		}
		return target;
	}

}

Skip refresh

To skip current refresh, just implement the condition logic into method skipWhen(ICachedDataBaseDao dao)

Example: Skip refresh if cache has been refreshened up to 10 seconds before

@Override
public boolean skipWhen(ICachedDataBaseDao<?> dao) {
	return System.currentTimeMillis()-dao.getLastRefreshTime()<10*DictPeriod.PERIOD_SECOND;
}

Example: Skip refresh if table count is the same:

@Override
public boolean skipWhen(ICachedDataBaseDao<?> dao) {
	return  Select.from(dao).noCache().countAny().intValue()==dao.result().size();
}

Example: Skip refresh if the yougest record dete is older:

@Override
public boolean skipWhen(ICachedDataBaseDao<?> dao) {
	return  hasTheYoungestDateBeforeLastRefReshDate(dao.colInsertDate());
}

In that way you can build by youself proper refresh functionality, suitable for your case.

Skip cache

Even if your DAO is cached, you can skip cache on demand. Just add noCache() method in your Select.

Select.from(daoPizza)
	.orderAscBy(daoPizza.colName())
	.noCache()
	.result();