Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Webfarm and a static cache (Asp.net)

  • 26-02-2008 9:33am
    #1
    Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭


    Given the below code, which stores key (GUID), value(String) pairs is static it only resides in one place in memory if I'm not mistaken. My question is how will this behave in a webfarm? I'd imagine there would be one static cache per webserver but I don't know how to test it to see exactly what happens.

    p.s. The code below is for illustration purposes only and is incomplete as a solution
    public static class ValueCache
    {
    	// Acts as the cache
    	private static Dictionary<Guid, String> cache = new Dictionary<Guid, String>();
    
    	/// <summary>
    	/// Returns the cached String for a given GUID. 
    	/// </summary>
    	internal static String getCache(Guid ID)
    	{
    		if (cache.ContainsKey(ID))
    		{
    			return cache[ID];
    		}
    		return null;
    	}
    
    	/// <summary>
    	/// Adds a String to the cache for a given GUID.
    	/// </summary>
    	internal static void AddToCache(Guid ID, String value)
    	{
    		cache[ID] = value;
    	}
    
    	/// <summary>
    	/// Clears the cache of all objects.
    	/// </summary>
    	internal static void ClearCache()
    	{
    		cache.Clear();
    	}
    }
    


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    If you're looking to keep a consistant cache across machines in the farm, it might be an idea to look at a solution like memcached.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    I'll have a look at that aidan but I don't thinks a goer for this particular problem.

    Anyway, I've scribbled this out on my jotter:

    If ServerA has a string value in its static cache (above) and the next request goes to ServerB that won't have value in its static cache will it? If that's the case then static cache solution won't work either.

    I don't think it will work with unique values which is what I'm caching. If the values weren't unique, like FieldInfo objects which is what I was originally using, then it would work. Oh well ...


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    You need to change the session state management from InProcess to SQL server when you go beyond one server.

    http://msdn2.microsoft.com/en-us/library/h6bb9cz9(VS.71).aspx

    Or use Dependency ideas to make sure that your Static Cache is synced

    Have a look at this article

    http://www.eggheadcafe.com/articles/20030420.asp

    I usually use the sessionState element when dealing with web farms for any session management i have dealt with.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Yeah, I'm going to do the same. Leave the session state management up to developers using the control seems to be the best solution.


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    You can always enable Sticky IPs on the NLB but to be honest, not a bad idea to implement the SQL Server or State server ideas


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    Ginger wrote: »
    You need to change the session state management from InProcess to SQL server when you go beyond one server.

    I posted a topic here a while ago, about losing session state across two webservers. Our router was supposed to stick a session to a server, but we never got it working. I went with the SQL state server, and it solved all the problems.


Advertisement