コード例 #1
0
        /// <summary>
        /// Puts a new entry to cache only if the specified key is absent.
        /// </summary>
        /// <typeparam name="V">Data type of Value</typeparam>
        /// <typeparam name="K">Data type of Key</typeparam>
        /// <param name="key">key</param>
        /// <param name="val">value</param>
        /// <param name="lifespaninMillis">Lifespan in milliseconds</param>
        /// <param name="maxIdleTimeinMillis">Maximum idle time in milliseconds</param>
        public V putIfAbsent <V, K>(K key, V val, int lifespaninMillis, int maxIdleTimeinMillis)
        {
            int lifespanSecs        = TimeSpan.FromMilliseconds(lifespaninMillis).Seconds;
            int maxIdleSecs         = TimeSpan.FromMilliseconds(maxIdleTimeinMillis).Seconds;
            PutIFAbsentOperation op = operationsFactory.newPutIfAbsentOperation(serializer.serialize(key), serializer.serialize(val), lifespanSecs, maxIdleSecs);

            transport = transportFactory.getTransport();
            try
            {
            }
            finally
            {
                transportFactory.releaseTransport(transport);
            }
            byte[] bytes = (byte[])op.executeOperation(transport);
            return((V)serializer.deserialize(bytes));
        }