, ... @stickfigure answer - Objectify. , . , Objectify ... , , ! , , , , , - .
, Objectify , . OfyService,
import static com.industryopenings.seeker.shared.OfyService.ofyw;
. ofyw(), ofy(). , ... ofyr() ofyw() . . .
OfyService ...
- ,
Objectify, ofyw(), cache(false) cache(true) clear() OFYW_USE_COUNT_THRESHOLD ofyw()
, ... . , ofyw() ( Objectify) .
import com.googlecode.objectify.*;
import com.googlecode.objectify.impl.ObjectifyImpl;
public final class OfyService {
public final static int OFYW_USE_COUNT_THRESHOLD = 10;
public static int currentReferenceCount = 0;
private static ObjectifyFactory defaultFactory = new ObjectifyFactory();
private static ObjectifyFactory noCacheFactory = new NoCacheFactory();
private static class NoCacheFactory extends ObjectifyFactory {
@Override
public Objectify begin() {
return new ObjectifyImpl<>(this).cache(false);
}
}
static {
defaultFactory.register(Doc.class);
defaultFactory.register(SiteLogEntry.class);
defaultFactory.register(SiteLogRunSummary.class);
noCacheFactory.register(Doc.class);
noCacheFactory.register(SiteLogEntry.class);
noCacheFactory.register(SiteLogRunSummary.class);
}
public static Objectify ofyr() {
ObjectifyService.setFactory(defaultFactory);
return ObjectifyService.ofy();
}
public static Objectify ofyw(){
ObjectifyService.setFactory(noCacheFactory);
currentReferenceCount++;
Objectify o = ObjectifyService.ofy();
if(currentReferenceCount > OFYW_USE_COUNT_THRESHOLD){
o.clear();
currentReferenceCount = 0;
}
return o;
}
}
, - .