public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
UICache uiCache = (UICache) component;
if(!uiCache.isDisabled()) {
ResponseWriter writer = context.getResponseWriter();
CacheProvider cacheProvider = RequestContext.getCurrentInstance().getApplicationContext().getCacheProvider();
String key = uiCache.getKey();
String region = uiCache.getRegion();
if(key == null) {
key = uiCache.getClientId(context);
}
if(region == null) {
region = context.getViewRoot().getViewId();
}
String output = (String) cacheProvider.get(region, key);
if(output == null) {
StringWriter stringWriter = new StringWriter();
ResponseWriter clonedWriter = writer.cloneWithWriter(stringWriter);
context.setResponseWriter(clonedWriter);
renderChildren(context, uiCache);
output = stringWriter.getBuffer().toString();
cacheProvider.put(region, key, output);
context.setResponseWriter(writer);
}
writer.write(output);
}