title: How do you check a token stored in a cache in asp.net
body: <p>so i am trying to check if a token exits in a cache but im not sure how to do so.
  Before i create the token and store it into the cache i want to check if it exists, if it exists i want to be able to use the same token instead of creating a new one.</p>
  <p>This is my code to create the token</p>
  <pre><code>public async Task&lt;ResponseHandler&gt; ExecuteAsync(XCommand command)
  {
     
      string token;
      ResponseHandler resp = new ResponseHandler();
      
      
           token = Guid.NewGuid().ToString(&quot;n&quot;);
  
          await CacheService.Cache(true, typeof(bool), token, null, TimeSpan.FromMinutes(1));
        
     // and then do something with the token
      return resp;
  
  }
  </code></pre>
  <p>so this is what i tried</p>
  <pre><code>public async Task&lt;VoucherResponseHandler&gt; ExecuteAsync(VoucherCommand command)
  {
      
      string token;
      ResponseHandler resp = new ResponseHandler();
      
      if (_distributedCacheService.Retrieve(token) == null) // i cant get it to check the token if its present it says use of unassigned local variable
      {
           token = Guid.NewGuid().ToString(&quot;n&quot;);
  
          await CacheService.Cache(true, typeof(bool), token, null, TimeSpan.FromMinutes(1));
        
      }
      else { 
      }
  
      return resp;
  }
  </code></pre>