class CachedCollection implements ICachedCollection {

    @Override
    public void upsert(final IObject message) throws UpsertCacheItemException {

        try {
            try (IPoolGuard poolGuard = new PoolGuard(connectionPool)) {
                Boolean isActive = isActiveField.in(message);
                isActiveField.out(message, true);
                IDatabaseTask upsertTask = IOC.resolve(
                    Keys.getOrAdd("db.cached_collection.upsert"),
                    poolGuard.getObject(),
                    collectionName,
                    message
                );
                try {
                    upsertTask.execute();
                } catch (TaskExecutionException e) {
                    isActiveField.out(message, isActive);
                    throw new UpsertCacheItemException("Error during execution upsert task.", e);
                }
            } catch (PoolGuardException e) {
                throw new UpsertCacheItemException("Can't get connection from pool.", e);
            } catch (InvalidArgumentException e) {
                throw new UpsertCacheItemException("Error during operate with isActive field.", e);
            }
            String key = specificKeyNameField.in(message);
            List<IObject> items = map.get(key);
            if (items != null && !items.isEmpty()) {
                Boolean isInsert = true;
                for (IObject obj : items) {
                    if (idField.in(obj).equals(idField.in(message))) {
                        items.remove(obj);
                        items.add(message);
                        isInsert = false;
                        break;
                    }
                }

                if (isInsert) {
                    items.add(message);
                }
            } else {
                map.put(key, new ArrayList<>(Arrays.asList(message)));
            }
        } catch (InvalidArgumentException | ReadValueException | ChangeValueException e) {
            throw new UpsertCacheItemException("Can't add or update cached object.", e);
        } catch (ResolutionException e) {
            throw new UpsertCacheItemException("Can't resolve cached object.", e);
        }
    }

    public  CachedCollection(final IObject config);

}