3 Replies Latest reply on Jul 5, 2010 6:28 AM by Michal Szymanski

    How to modify values of elements in cache and changing lifespan

    Michal Szymanski Newbie

      In our infinispan cache we are storing information about current user that are logged in to system, we store all information in Token object. It look similiar to this:

        • 1. Re: How to modify values of elements in cache and changing lifespan
          Michal Szymanski Newbie

          sorry by mistake I clicked 'Post' it is missing part of question:

           

          class Token {

              private String tokenStr;
              private Calendar validTill;
              private int validPeriod;

          }

           

          during loggin we set up validTill = when token expaire and what was initial validPeriod. When user make some activity we would like to change validTill adding validPeriod. Can I do it using this:


          Token token = tokenCache.get(tokenStr);

          Calendar tokenTime = Calendar.getInstance();

          tokenTime.add(Calendar.SECOND, token.getValidPeriod());
          token.setValidTill(tokenTime);

           

          in other words can I get element from token cache and change attributes of ths element or maybe I should get old one, create ne element with modified attributes , remove old one and put new one (or sould I use replace method?) ?

           

          Second question. Is it possible to exend lifespan value after creation of element e.g after few minutes  I would like exend expiration dat of token.

          • 2. Re: How to modify values of elements in cache and changing lifespan
            Mircea Markus Master
            in other words can I get element from token cache and change  attributes of ths element or maybe I should get old one, create ne  element with modified attributes , remove old one and put new one (or  sould I use replace method?) ?

            If you're using replicated/distribuetd caches you need to put the object in the cache  again, one way or the other (using replace or put). If you're using local caches you can operated on the object directly, witouth the need to re-put it into cache.

             

            Second question. Is it possible to exend lifespan value after  creation of element e.g after few minutes  I would like exend expiration  dat of token.

            Just put it again, with new value for expiration?