class DefaultAgentCache implements AgentCache {

    @Override
    public Single<AgentInstance> updateAgentInstanceStore(String instanceId, Function<AgentInstance, AgentInstance> function) {
        Single<AgentInstance> single = onEventLoopWithSubscription(() -> {
            AgentInstance agentInstance = getAgentInstance(instanceId);
            AgentInstance updatedAgentInstance = function.apply(agentInstance);
            setDataSnapshot(dataSnapshot.updateAgentInstance(updatedAgentInstance));
            eventSubject.onNext(new CacheUpdateEvent(CacheUpdateType.Instance, instanceId));
            return updatedAgentInstance;
        });
        return single.flatMap(ai -> agentStore.storeAgentInstance(ai).toSingle(() -> ai));
    }

    @Inject public  DefaultAgentCache(AgentManagementConfiguration configuration,
                             AgentStore agentStore,
                             InstanceCloudConnector connector,
                             Registry registry);
      DefaultAgentCache(AgentManagementConfiguration configuration,
                      AgentStore agentStore,
                      InstanceCloudConnector connector,
                      Registry registry,
                      Scheduler scheduler);

}