public void put()

in src/main/java/org/apache/geronimo/jcache/simple/SimpleCache.java [243:282]


    public void put(final K key, final V rawValue) {
        assertNotClosed();
        assertNotNull(key, "key");
        assertNotNull(rawValue, "value");

        final boolean storeByValue = config.isStoreByValue();
        final SimpleKey<K> simpleKey = new SimpleKey<>(storeByValue ? serializations.copy(manager.getClassLoader(), key) : key);
        final SimpleElement<V> oldElt = delegate.get(simpleKey);
        final V old = oldElt != null ? oldElt.getElement() : null;
        final V value = storeByValue ? serializations.copy(manager.getClassLoader(), rawValue) : rawValue;

        final boolean created = old == null;
        final Duration duration = created ? expiryPolicy.getExpiryForCreation() : expiryPolicy.getExpiryForUpdate();
        if (isNotZero(duration)) {
            final boolean statisticsEnabled = config.isStatisticsEnabled();
            final long start = Times.now(false);

            writer.write(new SimpleEntry<>(key, value));
            delegate.put(simpleKey, new SimpleElement<>(value, duration));
            if (!listeners.isEmpty()) {
                for (final SimpleListener<K, V> listener : listeners.values()) {
                    if (created) {
                        listener.onCreated(Collections.<CacheEntryEvent<? extends K, ? extends V>> singletonList(
                                new SimpleEvent<>(this, EventType.CREATED, null, key, value)));
                    } else
                        listener.onUpdated(Collections.<CacheEntryEvent<? extends K, ? extends V>> singletonList(
                                new SimpleEvent<>(this, EventType.UPDATED, old, key, value)));
                }
            }

            if (statisticsEnabled) {
                statistics.increasePuts(1);
                statistics.addPutTime(Times.now(false) - start);
            }
        } else {
            if (!created) {
                expires(simpleKey);
            }
        }
    }