func (store *Cache) ResignLeadership(leaderID string) common.SyncServiceError {
	return store.Store.ResignLeadership(leaderID)
}
ResignLeadership causes this sync service to give up the Leadership
package storage
import (
	"fmt"
	"io"
	"sync"
	"time"
	"github.com/open-horizon/edge-sync-service/common"
)
type Cache struct {
	destinations map[string]map[string]common.Destination
	Store        Storage
	lock         sync.RWMutex
}
func (store *Cache) Init() common.SyncServiceError {
	if err := store.Store.Init(); err != nil {
		return err
	}
	return store.cacheDestinations()
}
func (store *Cache) cacheDestinations() common.SyncServiceError {
	destinations, err := store.Store.RetrieveDestinations("", "")
	if err != nil {
		return &Error{"Failed to initialize the cache. Error: " + err.Error()}
	}
	store.lock.Lock()
	defer store.lock.Unlock()
	store.destinations = make(map[string]map[string]common.Destination, 0)
	for _, dest := range destinations {
		if store.destinations[dest.DestOrgID] == nil {
			store.destinations[dest.DestOrgID] = make(map[string]common.Destination, 0)
		}
		id := dest.DestType + ":" + dest.DestID
		store.destinations[dest.DestOrgID][id] = dest
	}
	return nil
}
func (store *Cache) Stop() {
	store.Store.Stop()
}
func (store *Cache) PerformMaintenance() {
	store.Store.PerformMaintenance()
}
func (store *Cache) Cleanup(isTest bool) common.SyncServiceError {
	return store.Store.Cleanup(isTest)
}
func (store *Cache) StoreObject(metaData common.MetaData, data []byte, status string) ([]common.StoreDestinationStatus, common.SyncServiceError) {
	return store.Store.StoreObject(metaData, data, status)
}
func (store *Cache) StoreObjectData(orgID string, objectType string, objectID string, dataReader io.Reader) (bool, common.SyncServiceError) {
	return store.Store.StoreObjectData(orgID, objectType, objectID, dataReader)
}
func (store *Cache) StoreObjectTempData(orgID string, objectType string, objectID string, dataReader io.Reader) (bool, common.SyncServiceError) {
	return store.Store.StoreObjectTempData(orgID, objectType, objectID, dataReader)
}
func (store *Cache) RemoveObjectTempData(orgID string, objectType string, objectID string) common.SyncServiceError {
	return store.Store.RemoveObjectTempData(orgID, objectType, objectID)
}
func (store *Cache) RetrieveTempObjectData(orgID string, objectType string, objectID string) (io.Reader, common.SyncServiceError) {
	return store.Store.RetrieveTempObjectData(orgID, objectType, objectID)
}
func (store *Cache) AppendObjectData(orgID string, objectType string, objectID string, dataReader io.Reader, dataLength uint32,
	offset int64, total int64, isFirstChunk bool, isLastChunk bool) common.SyncServiceError {
	return store.Store.AppendObjectData(orgID, objectType, objectID, dataReader, dataLength, offset, total, isFirstChunk, isLastChunk)
}
func (store *Cache) UpdateObjectStatus(orgID string, objectType string, objectID string, status string) common.SyncServiceError {
	return store.Store.UpdateObjectStatus(orgID, objectType, objectID, status)
}
func (store *Cache) UpdateObjectSourceDataURI(orgID string, objectType string, objectID string, sourceDataURI string) common.SyncServiceError {
	return store.Store.UpdateObjectSourceDataURI(orgID, objectType, objectID, sourceDataURI)
}
func (store *Cache) RetrieveObjectStatus(orgID string, objectType string, objectID string) (string, common.SyncServiceError) {
	return store.Store.RetrieveObjectStatus(orgID, objectType, objectID)
}
func (store *Cache) RetrieveObjectRemainingConsumers(orgID string, objectType string, objectID string) (int, common.SyncServiceError) {
	return store.Store.RetrieveObjectRemainingConsumers(orgID, objectType, objectID)
}
func (store *Cache) DecrementAndReturnRemainingConsumers(orgID string, objectType string, objectID string) (int,
	common.SyncServiceError) {
	return store.Store.DecrementAndReturnRemainingConsumers(orgID, objectType, objectID)
}
func (store *Cache) DecrementAndReturnRemainingReceivers(orgID string, objectType string, objectID string) (int,
	common.SyncServiceError) {
	return store.Store.DecrementAndReturnRemainingReceivers(orgID, objectType, objectID)
}
func (store *Cache) ResetObjectRemainingConsumers(orgID string, objectType string, objectID string) common.SyncServiceError {
	return store.Store.ResetObjectRemainingConsumers(orgID, objectType, objectID)
}
func (store *Cache) RetrieveUpdatedObjects(orgID string, objectType string, received bool) ([]common.MetaData, common.SyncServiceError) {
	return store.Store.RetrieveUpdatedObjects(orgID, objectType, received)
}
func (store *Cache) RetrieveObjectsWithDestinationPolicy(orgID string, received bool) ([]common.ObjectDestinationPolicy, common.SyncServiceError) {
	return store.Store.RetrieveObjectsWithDestinationPolicy(orgID, received)
}
func (store *Cache) RetrieveObjectsWithDestinationPolicyByService(orgID, serviceOrgID, serviceName string) ([]common.ObjectDestinationPolicy, common.SyncServiceError) {
	return store.Store.RetrieveObjectsWithDestinationPolicyByService(orgID, serviceOrgID, serviceName)
}
func (store *Cache) RetrieveObjectsWithDestinationPolicyUpdatedSince(orgID string, since int64) ([]common.ObjectDestinationPolicy, common.SyncServiceError) {
	return store.Store.RetrieveObjectsWithDestinationPolicyUpdatedSince(orgID, since)
}
func (store *Cache) RetrieveObjectsWithFilters(orgID string, destinationPolicy *bool, dpServiceOrgID string, dpServiceName string, dpPropertyName string, since int64, objectType string, objectID string, destinationType string, destinationID string, noData *bool, expirationTimeBefore string, deleted *bool) ([]common.MetaData, common.SyncServiceError) {
	return store.Store.RetrieveObjectsWithFilters(orgID, destinationPolicy, dpServiceOrgID, dpServiceName, dpPropertyName, since, objectType, objectID, destinationType, destinationID, noData, expirationTimeBefore, deleted)
}
func (store *Cache) RetrieveAllObjects(orgID string, objectType string) ([]common.ObjectDestinationPolicy, common.SyncServiceError) {
	return store.Store.RetrieveAllObjects(orgID, objectType)
}
func (store *Cache) RetrieveObjects(orgID string, destType string, destID string, resend int) ([]common.MetaData, common.SyncServiceError) {
	return store.Store.RetrieveObjects(orgID, destType, destID, resend)
}
func (store *Cache) RetrieveConsumedObjects() ([]common.ConsumedObject, common.SyncServiceError) {
	return store.Store.RetrieveConsumedObjects()
}
func (store *Cache) RetrieveObject(orgID string, objectType string, objectID string) (*common.MetaData, common.SyncServiceError) {
	return store.Store.RetrieveObject(orgID, objectType, objectID)
}
func (store *Cache) RetrieveObjectAndStatus(orgID string, objectType string, objectID string) (*common.MetaData, string, common.SyncServiceError) {
	return store.Store.RetrieveObjectAndStatus(orgID, objectType, objectID)
}
func (store *Cache) RetrieveObjectData(orgID string, objectType string, objectID string) (io.Reader, common.SyncServiceError) {
	return store.Store.RetrieveObjectData(orgID, objectType, objectID)
}
func (store *Cache) ReadObjectData(orgID string, objectType string, objectID string, size int, offset int64) ([]byte, bool, int, common.SyncServiceError) {
	return store.Store.ReadObjectData(orgID, objectType, objectID, size, offset)
}
func (store *Cache) CloseDataReader(dataReader io.Reader) common.SyncServiceError {
	return store.Store.CloseDataReader(dataReader)
}
func (store *Cache) MarkObjectDeleted(orgID string, objectType string, objectID string) common.SyncServiceError {
	return store.Store.MarkObjectDeleted(orgID, objectType, objectID)
}
func (store *Cache) MarkDestinationPolicyReceived(orgID string, objectType string, objectID string) common.SyncServiceError {
	return store.Store.MarkDestinationPolicyReceived(orgID, objectType, objectID)
}
func (store *Cache) ActivateObject(orgID string, objectType string, objectID string) common.SyncServiceError {
	return store.Store.ActivateObject(orgID, objectType, objectID)
}
func (store *Cache) GetObjectsToActivate() ([]common.MetaData, common.SyncServiceError) {
	return store.Store.GetObjectsToActivate()
}
func (store *Cache) DeleteStoredObject(orgID string, objectType string, objectID string) common.SyncServiceError {
	return store.Store.DeleteStoredObject(orgID, objectType, objectID)
}
func (store *Cache) DeleteStoredData(orgID string, objectType string, objectID string) common.SyncServiceError {
	return store.Store.DeleteStoredData(orgID, objectType, objectID)
}
func (store *Cache) CleanObjects() common.SyncServiceError {
	return store.Store.CleanObjects()
}
func (store *Cache) GetObjectDestinations(metaData common.MetaData) ([]common.Destination, common.SyncServiceError) {
	return store.Store.GetObjectDestinations(metaData)
}
func (store *Cache) UpdateObjectDeliveryStatus(status string, message string, orgID string, objectType string, objectID string,
	destType string, destID string) (bool, common.SyncServiceError) {
	return store.Store.UpdateObjectDeliveryStatus(status, message, orgID, objectType, objectID, destType, destID)
}
func (store *Cache) UpdateObjectDelivering(orgID string, objectType string, objectID string) common.SyncServiceError {
	return store.Store.UpdateObjectDelivering(orgID, objectType, objectID)
}
func (store *Cache) GetObjectDestinationsList(orgID string, objectType string,
	objectID string) ([]common.StoreDestinationStatus, common.SyncServiceError) {
	return store.Store.GetObjectDestinationsList(orgID, objectType, objectID)
}
func (store *Cache) UpdateObjectDestinations(orgID string, objectType string, objectID string, destinationsList []string) (*common.MetaData, string,
	[]common.StoreDestinationStatus, []common.StoreDestinationStatus, common.SyncServiceError) {
	return store.Store.UpdateObjectDestinations(orgID, objectType, objectID, destinationsList)
}
func (store *Cache) AddObjectDestinations(orgID string, objectType string, objectID string, destinationsList []string) (*common.MetaData, string,
	[]common.StoreDestinationStatus, common.SyncServiceError) {
	return store.Store.AddObjectDestinations(orgID, objectType, objectID, destinationsList)
}
func (store *Cache) DeleteObjectDestinations(orgID string, objectType string, objectID string, destinationsList []string) (*common.MetaData, string,
	[]common.StoreDestinationStatus, common.SyncServiceError) {
	return store.Store.DeleteObjectDestinations(orgID, objectType, objectID, destinationsList)
}
func (store *Cache) GetNumberOfStoredObjects() (uint32, common.SyncServiceError) {
	return store.Store.GetNumberOfStoredObjects()
}
func (store *Cache) AddWebhook(orgID string, objectType string, url string) common.SyncServiceError {
	return store.Store.AddWebhook(orgID, objectType, url)
}
func (store *Cache) DeleteWebhook(orgID string, objectType string, url string) common.SyncServiceError {
	return store.Store.DeleteWebhook(orgID, objectType, url)
}
func (store *Cache) RetrieveWebhooks(orgID string, objectType string) ([]string, common.SyncServiceError) {
	return store.Store.RetrieveWebhooks(orgID, objectType)
}
func (store *Cache) RetrieveDestinations(orgID string, destType string) ([]common.Destination, common.SyncServiceError) {
	store.lock.RLock()
	defer store.lock.RUnlock()
	result := make([]common.Destination, 0)
	if orgID == "" {
		for _, orgDests := range store.destinations {
			for _, value := range orgDests {
				if destType == "" || value.DestType == destType {
					result = append(result, value)
				}
			}
		}
	} else {
		for _, value := range store.destinations[orgID] {
			if destType == "" || value.DestType == destType {
				result = append(result, value)
			}
		}
	}
	return result, nil
}
func (store *Cache) DestinationExists(orgID string, destType string, destID string) (bool, common.SyncServiceError) {
	store.lock.RLock()
	defer store.lock.RUnlock()
	if _, ok := store.destinations[orgID][destType+":"+destID]; ok {
		return true, nil
	}
	return false, nil
}
func (store *Cache) StoreDestination(dest common.Destination) common.SyncServiceError {
	if err := store.Store.StoreDestination(dest); err != nil {
		return err
	}
	store.lock.Lock()
	defer store.lock.Unlock()
	if store.destinations[dest.DestOrgID] == nil {
		store.destinations[dest.DestOrgID] = make(map[string]common.Destination, 0)
	}
	store.destinations[dest.DestOrgID][dest.DestType+":"+dest.DestID] = dest
	return nil
}
func (store *Cache) DeleteDestination(orgID string, destType string, destID string) common.SyncServiceError {
	if err := store.Store.DeleteDestination(orgID, destType, destID); err != nil {
		return err
	}
	store.lock.Lock()
	defer store.lock.Unlock()
	delete(store.destinations[orgID], destType+":"+destID)
	return nil
}
func (store *Cache) UpdateDestinationLastPingTime(destination common.Destination) common.SyncServiceError {
	return store.Store.UpdateDestinationLastPingTime(destination)  
}
func (store *Cache) RemoveInactiveDestinations(lastTimestamp time.Time) {
	store.Store.RemoveInactiveDestinations(lastTimestamp)
	store.cacheDestinations()
}
func (store *Cache) GetNumberOfDestinations() (uint32, common.SyncServiceError) {
	return uint32(len(store.destinations)), nil
}
func (store *Cache) RetrieveDestination(orgID string, destType string, destID string) (*common.Destination, common.SyncServiceError) {
	store.lock.RLock()
	defer store.lock.RUnlock()
	if d, ok := store.destinations[orgID][destType+":"+destID]; ok {
		return &d, nil
	}
	return nil, &Error{fmt.Sprintf("Destination %s not found.", orgID+":"+destType+":"+destID)}
}
func (store *Cache) RetrieveDestinationProtocol(orgID string, destType string, destID string) (string, common.SyncServiceError) {
	store.lock.RLock()
	defer store.lock.RUnlock()
	if d, ok := store.destinations[orgID][destType+":"+destID]; ok {
		return d.Communication, nil
	}
	return "", &Error{fmt.Sprintf("Destination %s not found.", orgID+":"+destType+":"+destID)}
}
func (store *Cache) GetObjectsForDestination(orgID string, destType string, destID string) ([]common.ObjectStatus, common.SyncServiceError) {
	return store.Store.GetObjectsForDestination(orgID, destType, destID)
}
func (store *Cache) RetrieveAllObjectsAndUpdateDestinationListForDestination(orgID string, destType string, destID string) ([]common.MetaData, common.SyncServiceError) {
	return store.Store.RetrieveAllObjectsAndUpdateDestinationListForDestination(orgID, destType, destID)
}
func (store *Cache) RetrieveObjectAndRemovedDestinationPolicyServices(orgID string, objectType string, objectID string) (*common.MetaData, []common.ServiceID, common.SyncServiceError) {
	return store.Store.RetrieveObjectAndRemovedDestinationPolicyServices(orgID, objectType, objectID)
}
func (store *Cache) UpdateRemovedDestinationPolicyServices(orgID string, objectType string, objectID string, destinationPolicyServices []common.ServiceID) common.SyncServiceError {
	return store.Store.UpdateRemovedDestinationPolicyServices(orgID, objectType, objectID, destinationPolicyServices)
}
func (store *Cache) UpdateNotificationRecord(notification common.Notification) common.SyncServiceError {
	return store.Store.UpdateNotificationRecord(notification)
}
func (store *Cache) UpdateNotificationResendTime(notification common.Notification) common.SyncServiceError {
	return store.Store.UpdateNotificationResendTime(notification)
}
func (store *Cache) RetrieveNotificationRecord(orgID string, objectType string, objectID string, destType string,
	destID string) (*common.Notification, common.SyncServiceError) {
	return store.Store.RetrieveNotificationRecord(orgID, objectType, objectID, destType, destID)
}
func (store *Cache) DeleteNotificationRecords(orgID string, objectType string, objectID string,
	destType string, destID string) common.SyncServiceError {
	return store.Store.DeleteNotificationRecords(orgID, objectType, objectID, destType, destID)
}
func (store *Cache) RetrieveNotifications(orgID string, destType string, destID string, retrieveReceived bool) ([]common.Notification, common.SyncServiceError) {
	return store.Store.RetrieveNotifications(orgID, destType, destID, retrieveReceived)
}
func (store *Cache) RetrievePendingNotifications(orgID string, destType string, destID string) ([]common.Notification, common.SyncServiceError) {
	return store.Store.RetrievePendingNotifications(orgID, destType, destID)
}
func (store *Cache) InsertInitialLeader(leaderID string) (bool, common.SyncServiceError) {
	return store.Store.InsertInitialLeader(leaderID)
}
func (store *Cache) LeaderPeriodicUpdate(leaderID string) (bool, common.SyncServiceError) {
	return store.Store.LeaderPeriodicUpdate(leaderID)
}
func (store *Cache) RetrieveLeader() (string, int32, time.Time, int64, common.SyncServiceError) {
	return store.Store.RetrieveLeader()
}
func (store *Cache) UpdateLeader(leaderID string, version int64) (bool, common.SyncServiceError) {
	return store.Store.UpdateLeader(leaderID, version)
}