c# - Building a Cache Key quickly -


I am using a custom cache implementation in a Web API 2 application, this cache stores many thousands of items and A single API request can be read up to 10,000 times.

On the profile, I've found that the overall cache of each item is fully influenced by the performance.

Results from .NET Profiling:

Sampling Profiler

Cache Key Description:

I am creating the key of the item with a string hashing. Example:

  MySystem.MyProject.MyNamespace.MyClass.SomeMethod (44,6948)   

This is mixed in something like this, which is then used The caching framework is done as key (it is no longer used - refer to Edit 3):

  1bbbfeae-b143-77f2-8381-5ee11f5b9c0c  < / Pre> 

Obviously I need to ensure the specificity on each key, but without possibly presenting the possible duplication I have to improve the performance here Rica could not be found.

Main Builder:

  Public category CacheKeyBuilder {Private methodology rules; Public CacheKeyBuilder (MethodInterceptionArgs Input) {methodArguments = input; } // is no longer used - edit 3 public UINT 64 GetHashedKey () {hasfriendlyKey ()); } Public string GetFriendlyKey (if (methodArguments.Arguments.OfType & lt; IList & gt; (). {New ArgumentOutOfRangeException ("Ilsist can not make any key by type");} Var type = MethodArguments.Binding.GetType (); Var key = String.Format ("{0}. {1}. {2} {3} {4}", type .namespace, type.claimer.Name, methodArguments (Method: "Method"), type "Method.name" Choose method where x (x = & gt; x! = Null). (X = & gt; x.ToString ()). ToList (). Included Honitm ( "(", ")", ""))); Return key; } // is no longer used - edit 3 private UInt64 hash (string key) {UInt64 hashedValue = 3074457345618258791ul; For (int i = 0; i & lt; key.Length; i ++) {hashedValue + = key [i]; HashedValue * = 3074457345618258799ul; } Return handled; }}   

Thoughts:

  • Keyboard namespace, full type of name, generic and all assets to ensure uniqueness Values ​​are needed.
  • String.Format () essentially applies a stringbuilder , so it should be the most effective way of creating strings.
  • Did I get to havehing (new hash?), Which is faster than my earlier implementation

    Can any clear performance improvement be done that can be made?

    Edit:

    Another comment, based on the comments of David and Patrick, is that I can not harass the "code" string performance The reforms should be backwards compatible. I have to work with reflection.

    Edit 2:

    Sorry, hash methods are meant to return UInt64 . The code was fixed.

    Edit 3:

    Archiving key vs. hashed key does not make any difference in performance. Thus, I am only using GetFriendly () . Thanks usr

    It seems that your post is using SHARP. The method for caching generates the name as a string in at the time of compilation . It seems that you can get a fully qualified type name at the same time. It only allows reflection to be done at compile time.

      Public override zero compiled time start (Methodode method, AspectInfo aspectInfo) {_methodName = method.Name; _typeName = method.Binding.GetType (). Namespace ... ..name; // etc}   

    I stringbuilder Also try the append () vs string.Format () and see if there is any difference difference.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -