Default Membership Provider // Caching?

S

sloan

It looks like the default Membership Provider (and Role Provider) always
goes to the database to get its info.
(GetUsers, GetRoles, etc , etc).


I guess I'm going to roll my own, because I am going to need a cached
solution to avoid the database hits.
(My roles and users seldom/never change after a project rollout)

I wanted to ask in general (before I start the work of a custom membership
provider).

A. Am I right with my assumption? (no caching)
B. Is there some .config way to get caching from teh default providers that
I don't know about?
C. I really don't have any issue with ~~how the default ones work, just the
non caching. You think I might be able to use inheritance and just address
those issues?
D. If the above answers eventually lead to "roll your own", does anyone
know of a project/source showing a good "roll your own" solution.

I just got back from a long weekend trip in the car with my wife and 3 dogs.
So I'm a little on the "tuckered out" side today.


Thanks..............
 
G

Guest

Hmm, 1 wife and 3 dogs? That could be part of the problem.
Anyway, the only caching I know of is the CacheRolesInCookie directive.
If you really think you need caching (and in fact you may not really need it
at all, so you should test first under load), then you are going to have to
roll your own.
Scott Guthrie has some nice links to sample custom providers on his blog.

Peter
 
S

sloan

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;



}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top