コード例 #1
0
ファイル: Cache.cs プロジェクト: javithalion/NCache
        /// <summary>
        /// Set Attributes for a specific key in cache
        /// </summary>
        /// <param name="key">The key for which Attributes are set in the <see cref="Cache"/>.</param>        
        /// <para><b>Note:</b> If exceptions are enabled through the <see cref="ExceptionsEnabled"/> 
        /// setting, this property throws exception incase of failure.</para>
        /// </remarks>
        /// <exception cref="ArgumentNullException"><paramref name="key"/> contains a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="key"/> is not serializable.</exception>
        /// <example>The following example demonstrates how to set attributes for item in the <see cref="Cache"/>.
        /// <code>        
        /// CacheItemAttributes attrib=new CacheItemAttributes();
        /// attrib.AbsoluteExpiration=DateTime.Now.AddHours(10);
        /// Cache cache = NCache.InitializeCache("myCache");
        /// cache.SetAttributes("MyKey",attrib);
        /// </code>        
        /// </example>
        /// 
        public virtual bool SetAttributes(string key, CacheItemAttributes attributes)
        {
            if (key == null) throw new ArgumentNullException();

            if (attributes == null) throw new ArgumentNullException();

            return _cacheImpl.SetAttributes(key, attributes);
        }
コード例 #2
0
ファイル: RemoteCache.cs プロジェクト: javithalion/NCache
        public override bool SetAttributes(string key, CacheItemAttributes attributes)
        {
            AddAttributeCommand command = new AddAttributeCommand(key, attributes.AbsoluteExpiration);

            Request request = _broker.CreateRequest(command);
            _broker.ExecuteRequest(request);

            CommandResponse res = request.Response;
            res.ParseResponse();

            return res.OperationWasuccessfull();
        }
コード例 #3
0
        public OperationResult Touch(string key, long expirationTimeInSeconds)
        {
            if (string.IsNullOrEmpty(key))
                ThrowInvalidArgumentsException();

            OperationResult returnObject = new OperationResult();

            try
            {
               CacheItemAttributes attributes = new CacheItemAttributes();
                attributes.AbsoluteExpiration = CreateExpirationDate(expirationTimeInSeconds);
                bool result = _cache.SetAttributes(key, attributes);
                if (result)
                    returnObject = CreateReturnObject(Result.SUCCESS, null);
                else
                    returnObject = CreateReturnObject(Result.ITEM_NOT_FOUND, null);
            }
            catch (Exception e)
            {
                ThrowCacheRuntimeException(e);
            }
            return returnObject;
        }
コード例 #4
0
ファイル: InprocCache.cs プロジェクト: christrotter/NCache
        public override bool SetAttributes(string key, CacheItemAttributes attributes)
        {
            if (key == null) throw new ArgumentNullException("key");

            if (attributes == null) throw new ArgumentNullException("attributes");
            ExpirationHint hint = DependencyHelper.GetExpirationHint(attributes.AbsoluteExpiration, Cache.NoSlidingExpiration);
            return _nCache.AddExpirationHint(key, hint, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));

        }
コード例 #5
0
ファイル: CacheImplBase.cs プロジェクト: javithalion/NCache
 public virtual bool SetAttributes(string key, CacheItemAttributes attribute)
 {
     return false;
 }