Exemple #1
0
        /// <summary>
        /// Gets data async.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="callback">The callback.</param>
        internal static void GetAsync(string key, Action <object> callback)
        {
            var data = Get(key);

            if (data != null)
            {
                callback(data);
            }
            else
            {
                CacheItem cacheItem;

                if (!Container.TryGetValue(key, out cacheItem))
                {
                    var syncTask = new CacheAsyncTask
                    {
                        Key      = key,
                        Callback = callback
                    };

                    lock (syncObject)
                    {
                        PendingAsyncQueue.Enqueue(syncTask);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds the sync action.
        /// </summary>
        /// <param name="key">The cache item key for sync.</param>
        /// <param name="action">The sync action.</param>
        internal static void AddAsyncAction(string key, TimeSpan expires, Action <string, Action <object> > action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            lock (syncObject)
            {
                AsyncTasks[key] = new CacheAsyncTask {
                    Key = key, SyncAction = action, DataExpires = expires
                };
            }
        }