WCF Caching static data
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
精彩评论