Gets the cache for the given class

@param objectClass  The class to look up the cache for
@return             The cache
321158
private ObjectCache getCachePerClass(Class objectClass, int methodCall)
    {
        ObjectCache cache = (ObjectCache) cachesByClass.get(objectClass.getName());
        if (cache == null && methodCall == AbstractMetaCache.METHOD_CACHE)
        {
            /**
             * the cache wasn't found, and the cachesByClass didn't contain the key with a
             * null value, so create a new cache for this classtype
             */
            cache = new ObjectCacheJCSImpl(objectClass.getName());
            cachesByClass.put(objectClass.getName(), cache);
        }
        return cache;
    }
989612
public function getHydratorFor($objectClass)
    {
        if (! isset($this->hydratorInstances[$objectClass])) {

            $this->hydratorInstances[$objectClass] = $this->createHydratorFor($objectClass);
        }

        return $this->hydratorInstances[$objectClass];
    }
827349
public static function cached_object($obj, $class = null)
	{
		$class = $class ?: get_called_class();
		$id    = (is_int($obj) or is_string($obj)) ? (string) $obj : $class::implode_pk($obj);

		$result = ( ! empty(static::$_cached_objects[$class][$id])) ? static::$_cached_objects[$class][$id] : false;

		return $result;
	}
754292
public <T extends Serializable> T getStateObject(final Class<T> stateObjectClass) {
        return (T) stateObjects.get(stateObjectClass);
    }
1137651
protected DbEntity cacheFilter(DbEntity persistentObject) {
    DbEntity cachedPersistentObject = dbEntityCache.get(persistentObject.getClass(), persistentObject.getId());
    if (cachedPersistentObject!=null) {
      return cachedPersistentObject;
    }
    else {
      return persistentObject;
    }

  }
359537
public final static Class<?> getCompiledClass(String className, boolean useCache) throws CompilationException, ClassLoadException {
        try {
            if (! useCache) {
                
                /*String compilationResult = compileClass(className);
                System.out.println("************ compilationResult   " + compilationResult);
                if (compilationResult.contains("cannot read")) {
                    throw new ClassLoadException(compilationResult);
                }
                if (compilationResult.contains("error")) {
                    throw new CompilationException(compilationResult);
                }*/

                DynamicClassLoader dynamicClassLoader = new DynamicClassLoader(DynamicClassFactory.class.getClassLoader());
                return dynamicClassLoader.loadClass(className);
            } else {
                return CACHED_CONTROLLERS.computeIfAbsent(className, WRAP_FORNAME);
            }
        } catch (CompilationException e) {
            throw e; // so the exception doesn't get caught by the more general catch(Exception)
        } catch (Exception e) {
            throw new ClassLoadException(e);
        }
    }
1341101
public ObjectCacheDef setObjectCache(String name)
    {
        if ((_objectCache == null) || !_objectCache.getName().equals(name))
        {    
            _objectCache = new ObjectCacheDef(name);
    
            _objectCache.setOwner(this);
        }
        return _objectCache;
    }
19972
@SuppressWarnings("unchecked")
    protected <T> T lookup(Class<T> entityClass, Object id)
    {
        String key = cacheKey(entityClass, id);
        LOG.debug("Reading from L1 >> " + key);
        T o = (T) sessionCache.get(key);

        // go to second-level cache
        if (o == null)
        {
            LOG.debug("Reading from L2 >> " + key);
            Cache c = (Cache) getL2Cache();
            if (c != null)
            {
                o = (T) c.get(key);
                if (o != null)
                {
                    LOG.debug("Found item in second level cache!");
                }
            }
        }
        return o;
    }
856910
@Override
    protected final T retrieve(Object... args) {
        final K key = this.getKey(args);
        return this.objectCache.get(key);
    }
873638
private Class<?> loadClass(final String classname) throws PluginException {
        if (null == classname) {
            throw new IllegalArgumentException("A null java class name was specified.");
        }
        if (null != classCache.get(classname)) {
            return classCache.get(classname);
        }
        CachedJar cachedJar1 = getCachedJar();

        debug("loadClass! " + classname + ": " + cachedJar1.getCachedJar());
        final Class<?> cls;
        final URLClassLoader urlClassLoader = cachedJar1.getClassLoader();
        try {
            cls = Class.forName(classname, true, urlClassLoader);
            classCache.put(classname, cls);
        } catch (ClassNotFoundException e) {
            throw new PluginException("Class not found: " + classname, e);
        } catch (Throwable t) {
            throw new PluginException("Error loading class: " + classname, t);
        }
        return cls;
    }
1168258
public static ClassResolver weakCachingResolver(ClassLoader classLoader) {
        return new CachingClassResolver(
                new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
                new WeakReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
    }
1143687
public V getCachedObject(TaskRequest req, TaskResponse res, K key, Factory<K, V> factory) {
        final CacheMode cacheMode = CacheMode.valueOf((String) this.cacheModelPhrase.evaluate(req, res));
        
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Getting cached object for '" + key + "' using cache mode " + cacheMode + " and factory " + factory);
        }
        
        //Load the cache only if cache-all is enabled
        final ConcurrentMap<Tuple<Serializable, K>, Object> cache;
        final Tuple<Serializable, K> compoundCacheKey;
        switch (cacheMode) {
            case NONE: {
                return factory.createObject(key);
            }
            
            default:
            case ONE: {
                cache = null;
                compoundCacheKey = null;
            }
            break;
            
            case ALL: {
                cache = (ConcurrentMap<Tuple<Serializable, K>, Object>) this.cachePhrase.evaluate(req, res);
                final Serializable cacheNamespace = factory.getCacheNamespace(key);
                compoundCacheKey = new Tuple<Serializable, K>(cacheNamespace, key);
            }
            break;
        }
        
        //Determine the object to synchronize around
        final Object syncTarget = factory.getMutex(key);

        //get or create & cache the target object
        V instance = null;
        synchronized (syncTarget) {
            //Get the object from the local variables if no cache is available
            if (cache == null) {
                //Try for a thread-local instance first
                if (this.compareKeys(key, this.threadKeyHolder.get())) {
                    instance = this.threadInstanceHolder.get();
                }
                //Next try for a singleton instance
                else if (this.compareKeys(key, this.key)) {
                    instance = this.instance;
                } 
            }
            //Look in the passed cache for the instance
            else {
                final Object object = cache.get(compoundCacheKey);
                
                //If the cached object is a ThreadLocal use it for the instance
                if (object instanceof ThreadLocal<?>) {
                    instance = ((ThreadLocal<V>) object).get();
                }
                //If not assume it is the instance 
                else {
                    instance = (V) object;
                }
            }
            
            //If no instance was found create and cache one
            if (instance == null) {
                instance = factory.createObject(key);
                final boolean threadSafe = factory.isThreadSafe(key, instance);
                
                if (this.logger.isDebugEnabled()) {
                    this.logger.debug("Cache miss for '" + key + "' created '" + instance + "' threadSafe=" + threadSafe);
                }
                
                //If no cache is available store the instance in the local variables
                if (cache == null) {
                    if (threadSafe) {
                        this.instance = instance;
                        this.key = key;
                    }
                    else {
                        this.threadInstanceHolder.set(instance);
                        this.threadKeyHolder.set(key);
                    }
                }
                //Cache available store there
                else {
                    if (threadSafe) {
                        cache.put(compoundCacheKey, instance);
                    }
                    else {
                        ThreadLocal<V> threadInstanceHolder = (ThreadLocal<V>)cache.get(compoundCacheKey);
                        if (threadInstanceHolder == null) {
                            threadInstanceHolder = new ThreadLocal<V>();
                            
                            while (true) {
                                Object existing = cache.putIfAbsent(compoundCacheKey, threadInstanceHolder);
                                if (existing == null) {
                                    //nothing existed for that key, put was successful
                                    break;
                                }
                                
                                if (existing instanceof ThreadLocal) {
                                    //Existing ThreadLocal, just use it
                                    threadInstanceHolder = (ThreadLocal)existing;
                                    break;
                                }
                                
                                //something other than a ThreadLocal already exists, try replacing with the ThreadLocal
                                final boolean replaced = cache.replace(compoundCacheKey, threadInstanceHolder, existing);
                                if (replaced) {
                                    //Replace worked!
                                    break;
                                }
                                
                                //Replace didn't work, try the whole process again, yay non-blocking!
                            }
                            
                            if (cache instanceof EvictionAwareCache) {
                                ((EvictionAwareCache) cache).registerCacheEvictionListener(ThreadLocalCacheEvictionListener.INSTANCE);
                            }
                        }

                        threadInstanceHolder.set(instance);
                    }
                }
            }
            else if (this.logger.isDebugEnabled()) {
                this.logger.debug("Cache hit for '" + key + "' using '" + instance + "'");
            }
        }
        
        return instance;
    }
514000
public synchronized CacheObject get(Object key)
	{
		final CacheObject o = (CacheObject) map.get(key);
		if (o != null) {
			tree.remove(o);
			updateAccess(o);
			tree.put(o, o);
			++hits;
		}
		else
			++misses;
		return o;
	}
294522
public function getMetadata($objectClass)
    {
        if (! $objectClass instanceof ObjectKey) {
            $objectClass = new ObjectKey($objectClass);
        }

        $key = $objectClass->getKey();

        return $this->classMetadataFactory->loadMetadata(
            $objectClass,
            LoadingCriteria::createFromConfiguration($this->configuration, $objectClass),
            $this->configuration
        );
    }
406302
public static final ClassInfo get(Class<?> type) {
    ClassInfo exist = cache.get(type);
    if (null != exist) return exist;
    synchronized (cache) {
      exist = cache.get(type);
      if (null != exist) return exist;

      Set<MethodInfo> methods = CollectUtils.newHashSet();
      Class<?> nextClass = type;
      int index = 0;
      Map<String, Class<?>> nextParamTypes = null;
      while (null != nextClass && Object.class != nextClass) {
        Method[] declaredMethods = nextClass.getDeclaredMethods();
        for (int i = 0, n = declaredMethods.length; i < n; i++) {
          Method method = declaredMethods[i];
          if (!goodMethod(method)) continue;
          Type[] types = method.getGenericParameterTypes();
          Class<?>[] paramsTypes = new Class<?>[types.length];
          for (int j = 0; j < types.length; j++) {
            Type t = types[j];
            if (t instanceof ParameterizedType) {
              paramsTypes[j] = (Class<?>) ((ParameterizedType) t).getRawType();
            } else if (t instanceof TypeVariable) {
              paramsTypes[j] = nextParamTypes.get(((TypeVariable<?>) t).getName());
            } else {
              paramsTypes[j] = (Class<?>) t;
            }
            if (null == paramsTypes[j]) paramsTypes[j] = Object.class;
          }
          if (!methods.add(new MethodInfo(index++, method, paramsTypes))) index--;
        }

        Type nextType = nextClass.getGenericSuperclass();
        nextClass = nextClass.getSuperclass();
        if (nextType instanceof ParameterizedType) {
          Map<String, Class<?>> tmp = CollectUtils.newHashMap();
          Type[] ps = ((ParameterizedType) nextType).getActualTypeArguments();
          TypeVariable<?>[] tvs = nextClass.getTypeParameters();
          for (int k = 0; k < ps.length; k++) {
            if (ps[k] instanceof Class<?>) {
              tmp.put(tvs[k].getName(), (Class<?>) ps[k]);
            } else if (ps[k] instanceof TypeVariable) {
              tmp.put(tvs[k].getName(), nextParamTypes.get(((TypeVariable<?>) ps[k]).getName()));
            }
          }
          nextParamTypes = tmp;
        } else {
          nextParamTypes = Collections.emptyMap();
        }
      }
      exist = new ClassInfo(methods);
      cache.put(type, exist);
      return exist;
    }
  }
116857
public static ClassResolver weakCachingConcurrentResolver(ClassLoader classLoader) {
        return new CachingClassResolver(
                new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
                new WeakReferenceMap<String, Class<?>>(
                        PlatformDependent.<String, Reference<Class<?>>>newConcurrentHashMap()));
    }
694801
protected void preloadClass(final Class<?> objectClass) {
        try {
            Class.forName(objectClass.getName());
        } catch (final ClassNotFoundException e) {
            LOGGER.error(CLASS_NOT_FOUND, e, objectClass.getName());
        }
    }