Re: Default Membership Provider // Caching?



Here is some code to start (a future reader) out in the right direction:

I have a formal framework to cache data. So I had to leave that part out.
But the method are ensapsulated enough to get the idea.

If you're interested in my framework idea, check this out:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!125.entry

public class CachedSqlRoleProvider : SqlRoleProvider

{

private readonly string KEY_ALL_ROLES = "AllRolesKey";

private string[] GetCachedRoles()

{

//I have a Framework piece to cache data

//Implement your caching strategry here

return null;

}

private void CacheRoles(string[] roles)

{

//I have a Framework piece to cache data

//Implement your caching strategry here


}



public override string[] GetAllRoles()

{

string[] returnValues;


returnValues = this.GetCachedRoles();


//if there wasn't anything in the Cache, to use the base method to get a
fresh copy
if (null == returnValues)

{

//this will end up hitting the db
returnValues = base.GetAllRoles();

if (null != returnValues)

{

//we got them, cache them for next time

this.CacheRoles(returnValues);

}

}

return returnValues;



}

}


.