/// <inheritdoc /> public virtual void ClearOfType(string typeName) { var type = _typeFinder.GetTypeByName(typeName); if (type == null) { return; } var isInterface = type.IsInterface; try { EnterWriteLock(); foreach (var entry in GetDictionaryEntries() .Where(x => { // entry.Value is Lazy<object> and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null var value = SafeLazy.GetSafeLazyValue((Lazy <object>)x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) return(value == null || (isInterface ? (type.IsInstanceOfType(value)) : (value.GetType() == type))); }) .ToArray()) { RemoveEntry((string)entry.Key); } } finally { ExitWriteLock(); } }
/// <inheritdoc /> public void ClearOfType(string typeName) { var type = _typeFinder.GetTypeByName(typeName); if (type == null) { return; } var isInterface = type.IsInterface; foreach (var kvp in _items .Where(x => { // entry.Value is Lazy<object> and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null var value = SafeLazy.GetSafeLazyValue(x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) return(value == null || (isInterface ? (type.IsInstanceOfType(value)) : (value.GetType() == type))); })) { _items.TryRemove(kvp.Key, out _); } }
/// <inheritdoc /> public virtual void ClearOfType(string typeName) { var type = _typeFinder.GetTypeByName(typeName); if (type == null) { return; } var isInterface = type.IsInterface; try { _locker.EnterWriteLock(); foreach (var key in MemoryCache .Where(x => { // x.Value is Lazy<object> and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null var value = SafeLazy.GetSafeLazyValue((Lazy <object>)x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) return(value == null || (isInterface ? (type.IsInstanceOfType(value)) : (value.GetType() == type))); }) .Select(x => x.Key) .ToArray()) // ToArray required to remove { MemoryCache.Remove(key); } } finally { if (_locker.IsWriteLockHeld) { _locker.ExitWriteLock(); } } }
/// <summary> /// Creates a file system based Lucene <see cref="Lucene.Net.Store.Directory"/> with the correct locking guidelines for Umbraco /// </summary> /// <param name="folderName"> /// The folder name to store the index (single word, not a fully qualified folder) (i.e. Internal) /// </param> /// <returns></returns> public virtual Lucene.Net.Store.Directory CreateFileSystemLuceneDirectory(string folderName) { var dirInfo = new DirectoryInfo(Path.Combine(Current.IOHelper.MapPath(SystemDirectories.TempData), "ExamineIndexes", folderName)); if (!dirInfo.Exists) { System.IO.Directory.CreateDirectory(dirInfo.FullName); } //check if there's a configured directory factory, if so create it and use that to create the lucene dir var configuredDirectoryFactory = ConfigurationManager.AppSettings["Umbraco.Examine.LuceneDirectoryFactory"]; if (!configuredDirectoryFactory.IsNullOrWhiteSpace()) { //this should be a fully qualified type var factoryType = _typeFinder.GetTypeByName(configuredDirectoryFactory); if (factoryType == null) { throw new NullReferenceException("No directory type found for value: " + configuredDirectoryFactory); } var directoryFactory = (IDirectoryFactory)Activator.CreateInstance(factoryType); return(directoryFactory.CreateDirectory(dirInfo)); } //no dir factory, just create a normal fs directory var luceneDir = new SimpleFSDirectory(dirInfo); //we want to tell examine to use a different fs lock instead of the default NativeFSFileLock which could cause problems if the appdomain //terminates and in some rare cases would only allow unlocking of the file if IIS is forcefully terminated. Instead we'll rely on the simplefslock //which simply checks the existence of the lock file // The full syntax of this is: new NoPrefixSimpleFsLockFactory(dirInfo) // however, we are setting the DefaultLockFactory in startup so we'll use that instead since it can be managed globally. luceneDir.SetLockFactory(DirectoryFactory.DefaultLockFactory(dirInfo)); return(luceneDir); }