Example #1
0
        private FarmSettingStore GetSettingStore()
        {
            rrLock.EnterUpgradeableReadLock();

            try
            {
                //Attempt to reload if the settings store is null and a load hasn't been attempted, or if the last load interval is exceeded.
                //in the case of a refresh, then _settingStore will be null and missingSettings will be false.
                if ((_settingStore == null && missingSettings == false) || (DateTime.Now.Subtract(lastLoad).TotalSeconds) > cacheInterval)
                {
                    rrLock.EnterWriteLock();
                    try
                    {
                        //make sure first another thread didn't already load...before trying to load it.
                        if (_settingStore == null)
                        {
                            _settingStore   = FarmSettingStore.Load(farm);
                            lastLoad        = DateTime.Now;
                            missingSettings = (_settingStore == null);
                        }
                    }
                    finally
                    {
                        rrLock.ExitWriteLock();
                    }
                }

                return(_settingStore);
            }
            finally
            {
                rrLock.ExitUpgradeableReadLock();
            }
        }