title: ASP .NET Core using InMemory Cache per user
body: <p>I have a system where at some point, the user will be locked to a single page. In this situation his account his locked and he cannot be redirected to any other page and this is after authentication.</p>
  
  <p>The verification is done using Page Filters accessing database. To improve performance I have used memory cache. </p>
  
  <p>However, the result wasn't as expected because once the cache is used for a single user it will affect all the others.</p>
  
  <p>As far as i know, you can separate caching using tag helpers per user but I have no idea if this is possible using code</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; Iniciar(int paragemId, string paragem)
  {
      var registoId = Convert.ToInt32(User.GetRegistoId());
      if (await _paragemService.IsParagemOnGoingAsync(registoId))
      {
          return new JsonResult(new { started = false, message = "Já existe uma paragem a decorrer..." });
      }
      else
      {
          await _paragemService.RegistarInicioParagemAsync(paragemId, paragem, registoId);
          _registoService.UpdateParagem(new ProducaoRegisto(registoId)
          {
              IsParado = true
          });
  
          await _registoService.SaveChangesAsync();
          _cache.Set(CustomCacheEntries.RecordIsParado, true, DateTimeOffset.Now.AddHours(8));
  
          return new JsonResult(new { started = true, message = "Paragem Iniciada." });
      }
  }
  </code></pre>
  
  <p>here i only check first if the user account is blocked in the database first without checking cache first and then create the cache entry.</p>
  
  <p>Every user will be locked because of this.</p>
  
  <p>So my point is... Is there a way to achieve this like tag helpers?</p>