Is my cache being shared by the pages able to leave it per session?

Asked

Viewed 59 times

0

Good morning, you guys, So, I created a class to handle cache, but open the site in the same browser but with different users, one takes the cache from the other. how can I restrict by "session" that? Thank you !

Methods:

    public T GetKeyValue<T>(string key)
    {
        var cache = HttpContext.Current.Cache[key];
        if (cache != null)
            return (T)cache;

        return default(T);
    }

    public void SetKeyValue<T>(T obj, string key)
    {
        if (string.IsNullOrEmpty(key) || obj == null)
            return;

        HttpRuntime.Cache.Insert(key, obj,
                        null,
                        DateTime.Now.AddHours(1),
                        Cache.NoSlidingExpiration 
                        );
    }

UPDATE

When opening another tab, this method overwrites the "user" so all open sites take colors, styles, user settings you have... my doubt is, how to do this cache per user in a correct way, clean etc. because I concatenei but still sometimes breaks something

   public void Authenticate(string user)
    {
        if (CanAuthenticated(user))
        {
            this.User = user;
            this.Password = "password";
            var villaUser = this.SPAccessLogin.LogIn();
            this.VillaSiteUser = villaUser;
            this.IsAuthenticated = true;
        }
    }
  • 2

    can you give more details? Are you using this in the controller? Use Webapi? You can use sessionId and put it in the key of your cache, to separate the cache by user using this: HttpContext.Session.SessionID

  • Sorry for the delay, so I’m using cache only, currently I’m concatenating the user(eg.: vinicius_WebApiPath) to differentiate, but this was provisional, I wanted the cache to take a value that is unique from that tab, pq the site where I work he picks up the user by the domain viniciusImobiliaria.com.br => user = viniciusImobiliaria and from that I do everything that I have to do, because it’s a template, every user has a site for him with his domain. but the system q checks colors, styles and etc...

  • Well, the purpose of caching is to optimize something that will be used by multiple users. User cache makes no sense, it should be stored in a Session, which is the proper object for it. But you came to test the HttpContext.Session.SessionID ?

  • Sesssions is loaded into the iis pool, so if I have a thousand users I will have a thousand sesssions. dai yes it would not make sense, because I would end up with my server. and that’s the problem, we already have problems with Sessions...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.