//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="component">The <see cref="CopyFromIndexComponent"/> to which the indexed cache belongs</param> /// <param name="context">A context to use with the key and value XPath expressions</param> /// <param name="configuration">The configuration to use</param> protected IndexedCache(CopyFromIndexComponent component, XmlNamespaceManager context, XPathNavigator configuration) { if(component == null) throw new ArgumentNullException("component"); this.Component = component; // Get the name of the index this.Name = configuration.GetAttribute("name", String.Empty); if(String.IsNullOrWhiteSpace(this.Name)) component.WriteMessage(MessageLevel.Error, "Each index must have a unique name"); // Get the xpath for keys (relative to value nodes) string keyXPath = configuration.GetAttribute("key", String.Empty); if(String.IsNullOrWhiteSpace(keyXPath)) component.WriteMessage(MessageLevel.Error, "Each index element must have a key attribute " + "containing an XPath (relative to the value XPath) that evaluates to the entry key"); // Get the XPath for value nodes string valueXPath = configuration.GetAttribute("value", String.Empty); if(String.IsNullOrWhiteSpace(valueXPath)) component.WriteMessage(MessageLevel.Error, "Each index element must have a value attribute " + "containing an XPath that describes index entries"); try { this.KeyExpression = XPathExpression.Compile(keyXPath); } catch(XPathException) { component.WriteMessage(MessageLevel.Error, "The key expression '{0}' is not a valid XPath " + "expression", keyXPath); } this.KeyExpression.SetContext(context); try { this.ValueExpression = XPathExpression.Compile(valueXPath); } catch(XPathException) { component.WriteMessage(MessageLevel.Error, "The value expression '{0}' is not a valid XPath " + "expression", valueXPath); } this.ValueExpression.SetContext(context); }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="component">The <see cref="CopyFromIndexComponent"/> to which the indexed cache belongs</param> /// <param name="context">A context to use with the key and value XPath expressions</param> /// <param name="configuration">The indexed cache configuration</param> public InMemoryIndexedCache(CopyFromIndexComponent component, XmlNamespaceManager context, XPathNavigator configuration) : base(component, context, configuration) { string cacheValue = configuration.GetAttribute("cache", String.Empty); int size; if(String.IsNullOrWhiteSpace(cacheValue) || !Int32.TryParse(cacheValue, out size) || size < 1) size = 15; this.cacheSize = size; // Set up the cache queue = new ConcurrentQueue<string>(); cache = new ConcurrentDictionary<string, IndexedDocument>(4 * Environment.ProcessorCount, size); }