Last night I wrote up my first IHttpModule
to do some request processing. I'm using a regular expression to inspect the raw url. The IHttpModule
will be called on every request, so it seems reasonable to do some sort of caching of the regular expression object to prevent creation of it on every request.
Now my question... what is better: use the HttpContext.Current.Cache
to store the instantiated object or to use a private static Regex
in my module?
I'm looking forward to the reasons why. Just to clarify: the regex will never change and thus always be the same thing.