开发者

WCF Caching static data

开发者 https://www.devze.com 2023-03-08 02:37 出处:网络
I have a WCF service hosted in IIS. Every time any service method is called, a schema file is loaded to validate messages. I would like to cache schema file on service level so that every time service

I have a WCF service hosted in IIS. Every time any service method is called, a schema file is loaded to validate messages. I would like to cache schema file on service level so that every time service is called I am not reading the schema file. The schema loading logic looks like following:

Public  XmlSchemaSet GetSchema()
{
XmlSchemaSet schemaSet = new XmlSchemaSet();
Uri baseSchema = new Uri(AppDomain.CurrentDomain.BaseDirectory);
string mySchema = new Uri(baseSchema, "SchemaValidation.xsd").ToString();
XmlSchema schema = XmlSchema.Read(new XmlTextReader(mySchema), nul开发者_开发知识库l);
schemaSet.Add(schema);
return schemaSet

}

I would like to change this method to do following:

If(shema is in cache)

Read from cache and return

Else

Read schema from file, add to cache and return

Can somebody please help me on this.Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消