
// appMemory provides functions to read and write to the user app memory map.
// This map is lost when the application is closed, or the user is changed.
// An example of a memory entry is the CurrentViewedPage entry.

package appMemory

// Examples of memory entries include:
//	-AppUser (name of user who is signed in)
//	-CurrentViewedPage
//	-StopBuildMyMatches
//	-ViewedModeratorsReadyProgressStatus

import "sync"

var appMemoryMapMutex sync.RWMutex

var appMemoryMap map[string]string = make(map[string]string)

func ClearAppMemory(){

	appMemoryMapMutex.Lock()
	clear(appMemoryMap)
	appMemoryMapMutex.Unlock()
}

func SetMemoryEntry(key string, value string){

	appMemoryMapMutex.Lock()
	appMemoryMap[key] = value
	appMemoryMapMutex.Unlock()
}

func GetMemoryEntry(key string)(bool, string){

	appMemoryMapMutex.RLock()
	value, exists := appMemoryMap[key]
	appMemoryMapMutex.RUnlock()
	if (exists == false){
		return false, ""
	}

	return true, value
}

func DeleteMemoryEntry(key string){

	appMemoryMapMutex.Lock()
	delete(appMemoryMap, key)
	appMemoryMapMutex.Unlock()
}





