diff --git a/indra/llfilesystem/lldir.cpp b/indra/llfilesystem/lldir.cpp
index d26eb11542174deeb061044024612f7f3d617eb0..fed9c2e5041030abb175513b4094902ea04c738a 100644
--- a/indra/llfilesystem/lldir.cpp
+++ b/indra/llfilesystem/lldir.cpp
@@ -89,7 +89,8 @@ LLDir::LLDir()
 	mTempDir(""),
 	mDirDelimiter("/"), // fallback to forward slash if not overridden
 	mLanguage("en"),
-	mUserName("undefined")
+	mUserName("undefined"),
+	mGrid("")
 {
 }
 
@@ -916,7 +917,7 @@ std::string LLDir::getForbiddenFileChars()
 	return "\\/:*?\"<>|";
 }
 
-void LLDir::setLindenUserDir(const std::string &username)
+void LLDir::setLindenUserDir(const std::string &username, const std::string &gridname)
 {
 	// if the username isn't set, that's bad
 	if (!username.empty())
@@ -926,7 +927,13 @@ void LLDir::setLindenUserDir(const std::string &username)
 		std::string userlower(username);
 		LLStringUtil::toLower(userlower);
 		LLStringUtil::replaceChar(userlower, ' ', '_');
-		mLindenUserDir = add(getOSUserAppDir(), userlower);
+		std::string gridlower(gridname);
+		LLStringUtil::toLower(gridlower);
+		LLStringUtil::replaceChar(gridlower, ' ', '_');
+		const std::string& logname = (gridlower.empty())
+			? userlower : userlower.append(".").append(gridlower);
+		
+		mLindenUserDir = add(getOSUserAppDir(), logname);
 	}
 	else
 	{
@@ -950,10 +957,12 @@ void LLDir::setChatLogsDir(const std::string &path)
 
 void LLDir::updatePerAccountChatLogsDir()
 {
-	mPerAccountChatLogsDir = add(getChatLogsDir(), mUserName);
+	const std::string& logname = (mGrid.empty())
+		? mUserName : mUserName.append(".").append(mGrid);
+	mPerAccountChatLogsDir = add(getChatLogsDir(), logname);
 }
 
-void LLDir::setPerAccountChatLogsDir(const std::string &username)
+void LLDir::setPerAccountChatLogsDir(const std::string &username, const std::string &gridname)
 {
 	// if both first and last aren't set, assume we're grabbing the cached dir
 	if (!username.empty())
@@ -963,8 +972,12 @@ void LLDir::setPerAccountChatLogsDir(const std::string &username)
 		std::string userlower(username);
 		LLStringUtil::toLower(userlower);
 		LLStringUtil::replaceChar(userlower, ' ', '_');
-
+		std::string gridlower(gridname);
+		LLStringUtil::toLower(gridlower);
+		LLStringUtil::replaceChar(gridlower, ' ', '_');
+		
 		mUserName = userlower;
+		mGrid = gridlower;
 		updatePerAccountChatLogsDir();
 	}
 	else
@@ -1033,7 +1046,7 @@ bool LLDir::setCacheDir(const std::string &path)
 	if (path.empty() )
 	{
 		// reset to default
-		mCacheDir = "";
+		mCacheDir.clear();
 		return true;
 	}
 	else
diff --git a/indra/llfilesystem/lldir.h b/indra/llfilesystem/lldir.h
index 99e6ffb8bafb0a9d3030f48314571336b943326e..9035786e8157877e8ae9a89c5b78e930fdc7038d 100644
--- a/indra/llfilesystem/lldir.h
+++ b/indra/llfilesystem/lldir.h
@@ -184,8 +184,8 @@ class LLDir
 
 
 	virtual void setChatLogsDir(const std::string &path);		// Set the chat logs dir to this user's dir
-	virtual void setPerAccountChatLogsDir(const std::string &username);		// Set the per user chat log directory.
-	virtual void setLindenUserDir(const std::string &username);		// Set the linden user dir to this user's dir
+	virtual void setPerAccountChatLogsDir(const std::string &username, const std::string &gridname);		// Set the per user chat log directory.
+	virtual void setLindenUserDir(const std::string &username, const std::string &gridname);		// Set the linden user dir to this user's dir
 	virtual void setSkinFolder(const std::string &skin_folder, const std::string& language);
 	virtual std::string getSkinFolder() const;
 	virtual std::string getLanguage() const;
@@ -269,6 +269,7 @@ class LLDir
 	std::string mLLPluginDir;			// Location for plugins and plugin shell
     static std::string sDumpDir;            // Per-run crash report subdir of log directory.
 	std::string mUserName;				// Current user name
+	std::string mGrid;					// Current grid
 };
 
 void dir_exists_or_crash(const std::string &dir_name);
diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp
index 6224e45be0fee4c1f0335f59a180bbacac87834d..c5967f4d02b4aaf4ea57d88b5114c3ce4b37d9d3 100644
--- a/indra/llmessage/llexperiencecache.cpp
+++ b/indra/llmessage/llexperiencecache.cpp
@@ -88,10 +88,26 @@ const int LLExperienceCache::SEARCH_PAGE_SIZE     = 30;
 bool LLExperienceCache::sShutdown = false;
 
 //=========================================================================
-void LLExperienceCache::initSingleton()
+LLExperienceCache::LLExperienceCache(std::string grid)
 {
-    mCacheFileName = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "experience_cache.xml");
+    LLStringUtil::toLower(grid);
+    LLStringUtil::replaceChar(grid, ' ', '_');
 
+    std::string file;
+    if (grid.empty())
+    {
+        file = "experience_cache.xml";
+    }
+    else
+    {
+        file = llformat("experience_cache.%s.xml", grid);
+    }
+
+    mCacheFileName = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, file);
+}
+
+void LLExperienceCache::initSingleton()
+{
     LL_INFOS("ExperienceCache") << "Loading " << mCacheFileName << LL_ENDL;
     llifstream cache_stream(mCacheFileName.c_str());
 
diff --git a/indra/llmessage/llexperiencecache.h b/indra/llmessage/llexperiencecache.h
index b1fe4348a7e11b9e591634d56a8f3316c2e755bc..8f38ac316c65746f33cdd95ddccb2bb40673f11f 100644
--- a/indra/llmessage/llexperiencecache.h
+++ b/indra/llmessage/llexperiencecache.h
@@ -41,9 +41,9 @@ class LLSD;
 class LLUUID;
 
 
-class LLExperienceCache final : public LLSingleton < LLExperienceCache >
+class LLExperienceCache final : public LLParamSingleton < LLExperienceCache >
 {
-    LLSINGLETON_EMPTY_CTOR(LLExperienceCache);
+    LLSINGLETON(LLExperienceCache, std::string);
 
 public:
     typedef boost::function<std::string(const std::string &)> CapabilityQuery_t;
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 017b9c7627cf0838797b5e6da5abef8558860d1d..3a29a07a97f03eef6f472fc754b2b2ef5a50f3e8 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -4580,8 +4580,19 @@ void LLAppViewer::saveFinalSnapshot()
 void LLAppViewer::loadNameCache()
 {
 	// display names cache
+	std::string file;
+	if (LLGridManager::getInstance()->isInSecondlife())
+	{
+		file = "avatar_name_cache.xml";
+	}
+	else
+	{
+		std::string gridlabel = LLGridManager::getInstance()->getGridId();
+		LLStringUtil::toLower(gridlabel);
+		file = llformat("avatar_name_cache.%s.xml", gridlabel.c_str());
+	}
 	std::string filename =
-		gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "avatar_name_cache.xml");
+		gDirUtilp->getExpandedFilename(LL_PATH_CACHE, file);
 	LL_INFOS("AvNameCache") << filename << LL_ENDL;
 	llifstream name_cache_stream(filename.c_str());
 	if(name_cache_stream.is_open())
@@ -4596,8 +4607,19 @@ void LLAppViewer::loadNameCache()
 
 	if (!gCacheName) return;
 
-	std::string name_cache;
-	name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "name.cache");
+	std::string name_file;
+	if (LLGridManager::getInstance()->isInSecondlife())
+	{
+		name_file = "name.cache";
+	}
+	else
+	{
+		std::string gridid = LLGridManager::getInstance()->getGridId();
+		LLStringUtil::toLower(gridid);
+		name_file = llformat("name.%s.cache", gridid.c_str());
+	}
+
+	std::string name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, name_file);
 	llifstream cache_file(name_cache.c_str());
 	if(cache_file.is_open())
 	{
@@ -4608,8 +4630,19 @@ void LLAppViewer::loadNameCache()
 void LLAppViewer::saveNameCache()
 {
 	// display names cache
+	std::string file;
+	if (LLGridManager::getInstance()->isInSecondlife())
+	{
+		file = "avatar_name_cache.xml";
+	}
+	else
+	{
+		std::string gridlabel = LLGridManager::getInstance()->getGridId();
+		LLStringUtil::toLower(gridlabel);
+		file = llformat("avatar_name_cache.%s.xml", gridlabel.c_str());
+	}
 	std::string filename =
-		gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "avatar_name_cache.xml");
+		gDirUtilp->getExpandedFilename(LL_PATH_CACHE, file);
 	llofstream name_cache_stream(filename.c_str());
 	if(name_cache_stream.is_open())
 	{
@@ -4619,8 +4652,19 @@ void LLAppViewer::saveNameCache()
     // real names cache
 	if (gCacheName)
     {
-        std::string name_cache;
-        name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "name.cache");
+		std::string name_file;
+		if (LLGridManager::getInstance()->isInSecondlife())
+		{
+			name_file = "name.cache";
+		}
+		else
+		{
+			std::string gridid = LLGridManager::getInstance()->getGridId();
+			LLStringUtil::toLower(gridid);
+			name_file = llformat("name.%s.cache", gridid.c_str());
+		}
+
+        std::string name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, name_file);
         llofstream cache_file(name_cache.c_str());
         if(cache_file.is_open())
         {
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index f32bbad72ab1e3f9ecf985856c89e11144672af5..ed87dceece81011734314889cb0c4fb3fa4586da 100644
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -947,7 +947,8 @@ bool idle_startup()
          
 		// create necessary directories
 		// *FIX: these mkdir's should error check
-		gDirUtilp->setLindenUserDir(userid);
+		const std::string& gridlabel = !LLGridManager::getInstance()->isInSecondlife() ? LLGridManager::getInstance()->getGridId() : LLStringUtil::null;
+		gDirUtilp->setLindenUserDir(userid, gridlabel);
 		LLFile::mkdir(gDirUtilp->getLindenUserDir());
 
 		// As soon as directories are ready initialize notification storages
@@ -995,7 +996,7 @@ bool idle_startup()
 		{
 			gDirUtilp->setChatLogsDir(gSavedPerAccountSettings.getString("InstantMessageLogPath"));		
 		}
-		gDirUtilp->setPerAccountChatLogsDir(userid);  
+		gDirUtilp->setPerAccountChatLogsDir(userid, gridlabel);
 		
 		LLFile::mkdir(gDirUtilp->getChatLogsDir());
 		LLFile::mkdir(gDirUtilp->getPerAccountChatLogsDir());
@@ -2934,6 +2935,8 @@ void LLStartUp::initNameCache()
 void LLStartUp::initExperiences()
 {   
     // Should trigger loading the cache.
+	const std::string& gridlabel = !LLGridManager::getInstance()->isInSecondlife() ? LLGridManager::getInstance()->getGridId() : LLStringUtil::null;
+	LLExperienceCache::initParamSingleton(gridlabel);
     LLExperienceCache::instance().setCapabilityQuery(
         boost::bind(&LLAgent::getRegionCapability, &gAgent, _1));