Class CachingServiceImpl

    • Field Detail

      • cacheManager

        protected net.sf.ehcache.CacheManager cacheManager
        The underlying cache manager; injected.
    • Constructor Detail

      • CachingServiceImpl

        public CachingServiceImpl()
    • Method Detail

      • getRequestCaches

        protected Map<String,​MapCache> getRequestCaches()
        Returns:
        the current request map which is bound to the current thread
      • unbindRequestCaches

        public void unbindRequestCaches()
        Unbinds all request caches. Destroys the caches completely.
        Specified by:
        unbindRequestCaches in interface CachingService
      • setConfigurationService

        @Autowired(required=true)
        public void setConfigurationService​(ConfigurationService configurationService)
      • setRequestService

        @Autowired
        public void setRequestService​(RequestService requestService)
      • setServiceManager

        @Autowired(required=true)
        public void setServiceManager​(ServiceManager serviceManager)
      • setCacheManager

        @Autowired(required=true)
        public void setCacheManager​(net.sf.ehcache.CacheManager cacheManager)
      • getCacheManager

        public net.sf.ehcache.CacheManager getCacheManager()
      • reloadConfig

        protected void reloadConfig()
        Reloads the configuration settings from the configuration service.
      • notifyForConfigNames

        public String[] notifyForConfigNames()
        Description copied from interface: ConfigChangeListener
        Allows the listener to filter the change notifications so it is only notified when the named configuration items change. For example, if this method returns an array containing "upload.enabled" then whenever this configuration setting changes the listener will be called. If any other settings change the listener will not be called unless they are specific bean properties for this service (e.g. [email protected]). If you want to be notified when any configuration setting changes then simply return a null or an empty string and the listener will be called for every configuration update.
        Specified by:
        notifyForConfigNames in interface ConfigChangeListener
        Returns:
        an array of configuration string names (e.g. {"system.name","upload.enabled"}) OR null/empty to be notified for every configuration setting that changes
      • configurationChanged

        public void configurationChanged​(List<String> changedSettingNames,
                                         Map<String,​String> changedSettings)
        Description copied from interface: ConfigChangeListener
        Called whenever the configuration settings change (depending on the filter). This will only be called once for each config update regardless of the number of settings that were actually changed.

        NOTE: This will strip off the beanName from any service property settings. Example: [email protected] => downloadEnabled

        Specified by:
        configurationChanged in interface ConfigChangeListener
        Parameters:
        changedSettingNames - includes the names of all settings that changed
        changedSettings - includes the map of all settings that changed
      • notifyForTypes

        public Class<?>[] notifyForTypes()
        Description copied from interface: ServiceChangeListener
        Allows filtering so that notifications are only sent when classes implement one of the types specified. The listener method will only be called once regardless of how many types match.

        Just return null or empty array to be notified for all service registrations.

        Specified by:
        notifyForTypes in interface ServiceChangeListener
        Returns:
        an array of classes OR null to be notified of all service registrations
      • serviceRegistered

        public void serviceRegistered​(String serviceName,
                                      Object service,
                                      List<Class<?>> implementedTypes)
        Description copied from interface: ServiceChangeListener
        This will be called when services are newly registered with the service manager. It will not be called when the core services are starting up though.

        It is not called until the service is fully initialized. It is called once and only once per service that is registered.

        Specified by:
        serviceRegistered in interface ServiceChangeListener
        Parameters:
        serviceName - the name of the service
        service - the service bean
        implementedTypes - a list of all the class types which this service implements
      • init

        @PostConstruct
        public void init()
      • shutdown

        @PreDestroy
        public void shutdown()
      • destroyCache

        public void destroyCache​(String cacheName)
        Description copied from interface: CachingService
        Flushes and destroys the cache with this name. Generally there is no reason to call this.
        Specified by:
        destroyCache in interface CachingService
        Parameters:
        cacheName - the unique name for this cache (e.g. org.dspace.user.UserCache)
      • getCache

        public Cache getCache​(String cacheName,
                              CacheConfig cacheConfig)
        Description copied from interface: CachingService
        Construct a Cache with the given name OR retrieve the one that already exists with this name. Often the name is the fully qualified classpath of the API for the service that is being cached, or of the class if there is no API. This will operate on system defaults (probably a distributed cache without replication) OR it will use the defaults which are configured for this cacheName (part of the underlying implementation) if the cacheConfig is null.

        This can only retrieve request caches for the current request.

        If the cache already exists then the cacheConfig is ignored.

        Specified by:
        getCache in interface CachingService
        Parameters:
        cacheName - the unique name for this cache (e.g. org.dspace.user.UserCache)
        cacheConfig - defines the configuration for this cache
        Returns:
        a cache which can be used to store objects
      • getCaches

        public List<Cache> getCaches()
        Description copied from interface: CachingService
        Gets all the caches that the service knows about. This will include caches of all scopes but only includes request caches for the current thread.
        Specified by:
        getCaches in interface CachingService
        Returns:
        a list of all the caches which the caching service knows about
      • getStatus

        public String getStatus​(String cacheName)
        Description copied from interface: CachingService
        Get a status report of cache usage which is suitable for log or screen output.
        Specified by:
        getStatus in interface CachingService
        Parameters:
        cacheName - (optional) the unique name for this cache (e.g. org.dspace.user.UserCache) OR null for status of all caches
        Returns:
        a string representing the current status of the specified cache or all caches
      • resetCaches

        public void resetCaches()
        Description copied from interface: CachingService
        Clears all caches. Generally there is no reason to call this.
        Specified by:
        resetCaches in interface CachingService
      • getAllEhCaches

        protected List<net.sf.ehcache.Ehcache> getAllEhCaches​(boolean sorted)
        Return all caches from the CacheManager.
        Parameters:
        sorted - if true then sort by name
        Returns:
        the list of all known ehcaches
      • instantiateEhCache

        protected EhcacheCache instantiateEhCache​(String cacheName,
                                                  CacheConfig cacheConfig)
        Create an EhcacheCache (and the associated EhCache) using the supplied name (with default settings), or get the cache out of Spring or the current configured cache.

        This expects that the cacheRecord has already been checked and will not check it again.

        Will proceed in this order:

        1. Attempt to load a bean with the name of the cache
        2. Attempt to load cache from caching system
        3. Create a new cache by this name
        4. Put the cache in the cache record
        Parameters:
        cacheName - the name of the cache
        cacheConfig - the config for this cache
        Returns:
        a cache instance
      • instantiateMapCache

        protected MapCache instantiateMapCache​(String cacheName,
                                               CacheConfig cacheConfig)
        Create a thread map cache using the supplied name with supplied settings.

        This expects that the cacheRecord has already been checked and will not check it again. It also places the cache into the request map.

        Parameters:
        cacheName - the name of the cache
        cacheConfig - the config for this cache
        Returns:
        a cache instance
      • generateCacheStats

        protected static String generateCacheStats​(net.sf.ehcache.Ehcache cache)
        Generate some stats for this cache. Note that this is not cheap so do not use it very often.
        Parameters:
        cache - an Ehcache
        Returns:
        the stats of this cache as a string