dinesh94 / simple-spring-memcached

Automatically exported from code.google.com/p/simple-spring-memcached
MIT License
0 stars 0 forks source link

Using the Cache Outside of Annotation Context #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
For testing purpose I wanted to use the cache without having to use annotation. 
Is there any particular reason why I couldn't do the following?

public class CachingServiceTest {

   @Autowired
   com.google.code.ssm.CacheFactory cacheFactory;

    @Test
    public void testGetCache() throws Exception {
       Cache result = cachingService.getCache();
       assertNotNull(result);
    }
}

If i run the above unit test I run into "This factory has already created 
memcached client" error.

Maybe I misunderstand how to do something similar to the above but it would be 
really nice to be able to do manipulation and checking of the cache without 
having to use annotations.

Original issue reported on code.google.com by mark.a...@gmail.com on 19 Jun 2012 at 7:23

GoogleCodeExporter commented 9 years ago

Original comment by ragno...@gmail.com on 2 Jul 2012 at 6:54

GoogleCodeExporter commented 9 years ago
Which SSM version do you use?

Regardless of version if it is one of the latest then you can still use cache 
without annotations. To do it instead of injecting 
com.google.code.ssm.CacheFactory inject com.google.code.ssm.Cache object. If 
you use more the one CacheFactory then you have to use @Qualifier:

  public class CachingServiceTest {

   @Autowired
   //@Qualifier("defaultMemcachedClient")
   com.google.code.ssm.Cache cache;

    @Test
    public void testGetCache() throws Exception {
       Cache result = cache;
       assertNotNull(result);
    }
}

Does it fulfill your requirements?
You can also inject CacheFactory but cannot call getCache() or getObject().

Original comment by ragno...@gmail.com on 3 Jul 2012 at 3:52

GoogleCodeExporter commented 9 years ago
The issue is closed because of no activity. 

Original comment by ragno...@gmail.com on 30 Sep 2012 at 7:09