code: public static void cacheCriteriaByMapping(Class<?> targetClass, Criteria criteria) {
          Mapping m = GrailsDomainBinder.getMapping(targetClass);
          if (m != null && m.getCache() != null && m.getCache().getEnabled()) {
              criteria.setCacheable(true);
          }
      }
docs: Configures the criteria instance to cache based on the configured mapping.
  
  @param targetClass The target class
  @param criteria The criteria