1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.cache.internal

File DefaultCacheManager.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

0
10
6
1
114
55
7
0.7
1.67
6
1.17

Classes

Class Line # Actions
DefaultCacheManager 44 10 0% 7 3
0.812581.2%
 

Contributing tests

This file is covered by 87 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.cache.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Singleton;
24   
25    import org.xwiki.cache.Cache;
26    import org.xwiki.cache.CacheException;
27    import org.xwiki.cache.CacheFactory;
28    import org.xwiki.cache.CacheManager;
29    import org.xwiki.cache.CacheManagerConfiguration;
30    import org.xwiki.cache.config.CacheConfiguration;
31    import org.xwiki.component.annotation.Component;
32    import org.xwiki.component.manager.ComponentLookupException;
33    import org.xwiki.component.manager.ComponentManager;
34   
35    /**
36    * The default implementation of CacheManager. It uses ConfigurationManager to find the cache an local cache hints to
37    * use to lookup cache components.
38    *
39    * @version $Id: 6f2cb8385a47161f47111443549a47fbb5d67539 $
40    * @since 1.7M1
41    */
42    @Component
43    @Singleton
 
44    public class DefaultCacheManager implements CacheManager
45    {
46    /**
47    * The component manager to use to find cache components.
48    */
49    @Inject
50    private ComponentManager componentManager;
51   
52    /**
53    * The configuration component for {@link CacheManager}.
54    */
55    @Inject
56    private CacheManagerConfiguration configuration;
57   
 
58  193 toggle @Override
59    public CacheFactory getCacheFactory() throws ComponentLookupException
60    {
61  193 return getCacheFactory(this.configuration.getDefaultCache());
62    }
63   
 
64  0 toggle @Override
65    public CacheFactory getLocalCacheFactory() throws ComponentLookupException
66    {
67  0 return getCacheFactory(this.configuration.getDefaultLocalCache());
68    }
69   
70    /**
71    * Lookup the cache creation component with provided hint return it.
72    *
73    * @param cacheHint the role hint to lookup.
74    * @return a cache creation service.
75    * @throws ComponentLookupException error when searching for cache component.
76    */
 
77  193 toggle public CacheFactory getCacheFactory(String cacheHint) throws ComponentLookupException
78    {
79  193 return this.componentManager.getInstance(CacheFactory.class, cacheHint);
80    }
81   
 
82  1141 toggle @Override
83    public <T> Cache<T> createNewCache(CacheConfiguration config) throws CacheException
84    {
85  1141 return createNewCache(config, this.configuration.getDefaultCache());
86    }
87   
 
88  6 toggle @Override
89    public <T> Cache<T> createNewLocalCache(CacheConfiguration config) throws CacheException
90    {
91  6 return createNewCache(config, this.configuration.getDefaultLocalCache());
92    }
93   
94    /**
95    * Lookup the cache component with provided hint and create a new cache.
96    *
97    * @param <T> the class of the data stored in the cache.
98    * @param config the cache configuration.
99    * @param cacheHint the role hint to lookup.
100    * @return a new {@link Cache}.
101    * @throws CacheException error when creating the cache.
102    */
 
103  1147 toggle public <T> Cache<T> createNewCache(CacheConfiguration config, String cacheHint) throws CacheException
104    {
105  1147 CacheFactory cacheFactory;
106  1147 try {
107  1147 cacheFactory = this.componentManager.getInstance(CacheFactory.class, cacheHint);
108    } catch (ComponentLookupException e) {
109  0 throw new CacheException("Failed to get cache factory for role hint [" + cacheHint + "]", e);
110    }
111   
112  1147 return cacheFactory.newCache(config);
113    }
114    }