Cache CryptokiCollection for performance

11/1/2017 2:03:06 PM
Gravatar
Total Posts 1

Cache CryptokiCollection for performance

Hi,

I am trying to improve performance of PDF Signing and searching for private key takes few seconds. I was thinking to cache this private key on first search and keep it for sliding cache.

Snippet

public CryptokiCollection findTarget(Session session, string label) {     

if (cache.Contains(label))     {         

return (CryptokiCollection)cache.Get(label);     

}     else     {         

CryptokiCollection template = new CryptokiCollection();         

template.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, label));         

template.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_PRIVATE_KEY));         

template.Add(new ObjectAttribute(ObjectAttribute.CKA_KEY_TYPE, Key.CKK_RSA));         

var pk = session.Objects.Find(template, 1);         

 

// Store data in the cache         

CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();         

cacheItemPolicy.SlidingExpiration = TimeSpan.FromHours(4);         

cache.Add(label, pk, cacheItemPolicy);         return pk;     

}

}

Is it ok to store this CryptokiCollection  in .Net Cache ?

Please advise ?