Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8352447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:57:46+00:00 2026-06-09T08:57:46+00:00

I am using Spring3.1 in standalone Env. I am caching my entry using @Cachable

  • 0

I am using Spring3.1 in standalone Env.
I am caching my entry using @Cachable annotation.

Sometimes I need to iterate on the caching list in order to get specific value(not key).

So I managed to retrieve the cached list but how could I iterate on it’s elements.

private ClientDTO getClientDTOByClientId(Integer clientId)
{

    Cache clientCache = null;
    try
    {
        clientCache = ehCacheCacheManager.getCache("client");

          //need here to iterate on clientCache. how?


    }
    catch (Exception e)
    {
        log.error("Couldnt retrieve client from cache. clientId=" + clientId);
    }
    return clientDTO;
}

I using ehcache mechanism.

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
        p:cache-manager-ref="ehcache" />

    <bean id="ehcache"
        class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
        p:config-location="classpath:ehcache.xml" />

thanks,
ray.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:57:48+00:00Added an answer on June 9, 2026 at 8:57 am

    CacheManager.getCache() returns a net.sf.ehcache.Cache, which has a getKeys() method that returns a list of cache keys that you can iterate over. To retrieve the actual object that’s been stored (as opposed to the wrapped net.sf.ehcache.Element), use the Element.getObjectValue().

    EDIT:
    According to Spring it doesn’t look like they will ever support Cache.getKeys(), so you’ll have to cast to the underlying provider.

    Something like this:

    public boolean contains(String cacheName, Object o) {
      net.sf.ehcache.EhCache cache = (net.sf.ehcache.EhCache) org.springframework.cache.CacheManager.getCache(cacheName).getNativeCache();
      for (Object key: cache.getKeys()) {
        Element element = cache.get(key);
        if (element != null && element.getObjectValue().equals(o)) {
          return true;
        }
      }
      return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Spring3.1 in standalone Env. I am trying to cache my entries.
I am using Spring3.1 in a standalone env. Although I am using Spring I
I am using Spring3.1 on standalone env. I set topic with jms templates this
I developing under Spring3.1 standalone env. I am trying to connect my application remotely
I a working on a JSF2/Spring3/JPA2 project using facelets as view technology. javax.faces.DEFAULT_SUFFIX is
I'm trying to create a standalone app using JBoss Microcontainer for IoC and JBoss
I asked a question yesterday ( Using Spring in standalone apps ) on how
I'm having some issues with Jetty7 standalone and my spring web app using jsp/jstl/el.
I am using hsqldb standalone as my database. i have a hsqldb.jar(hsqldb-2.0.0) which i
Is it possible to use bitronix.tm.resource.jdbc.PoolingDataSource without using bitronix transaction manager and using standalone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.