Added a primitive but seemingly effective store name cache. Switching the

stores table to a synthetic primary key caused a 15% performance drop. This gets
that performance back, plus or minus.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4493 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-12-02 20:53:33 +00:00
parent b8ff632f15
commit b19c40939f
3 changed files with 41 additions and 1 deletions

View File

@@ -754,6 +754,7 @@ public class AVMRepository
} }
AVMDAOs.Instance().fAVMStorePropertyDAO.delete(store); AVMDAOs.Instance().fAVMStorePropertyDAO.delete(store);
AVMDAOs.Instance().fAVMStoreDAO.delete(store); AVMDAOs.Instance().fAVMStoreDAO.delete(store);
AVMDAOs.Instance().fAVMStoreDAO.invalidateCache();
} }
/** /**
@@ -2261,5 +2262,6 @@ public class AVMRepository
} }
store.setName(destName); store.setName(destName);
fLookupCache.onDelete(sourceName); fLookupCache.onDelete(sourceName);
AVMDAOs.Instance().fAVMStoreDAO.invalidateCache();
} }
} }

View File

@@ -69,4 +69,9 @@ public interface AVMStoreDAO
* @return The store. * @return The store.
*/ */
public AVMStore getByID(long id); public AVMStore getByID(long id);
/**
* Invalidate the by name lookup cache.
*/
public void invalidateCache();
} }

View File

@@ -17,7 +17,9 @@
package org.alfresco.repo.avm.hibernate; package org.alfresco.repo.avm.hibernate;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.alfresco.repo.avm.AVMNode; import org.alfresco.repo.avm.AVMNode;
import org.alfresco.repo.avm.AVMStore; import org.alfresco.repo.avm.AVMStore;
@@ -33,12 +35,18 @@ import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
class AVMStoreDAOHibernate extends HibernateDaoSupport implements class AVMStoreDAOHibernate extends HibernateDaoSupport implements
AVMStoreDAO AVMStoreDAO
{ {
/**
* An in memory cache of name to primary key mappings.
*/
private Map<String, Long> fNameCache;
/** /**
* Do nothing constructor. * Do nothing constructor.
*/ */
public AVMStoreDAOHibernate() public AVMStoreDAOHibernate()
{ {
super(); super();
fNameCache = new HashMap<String, Long>();
} }
/** /**
@@ -77,10 +85,27 @@ class AVMStoreDAOHibernate extends HibernateDaoSupport implements
*/ */
public AVMStore getByName(String name) public AVMStore getByName(String name)
{ {
Long id = null;
synchronized (this)
{
id = fNameCache.get(name);
}
if (id != null)
{
return (AVMStore)getSession().get(AVMStoreImpl.class, id);
}
Query query = getSession().createQuery("from AVMStoreImpl st " + Query query = getSession().createQuery("from AVMStoreImpl st " +
"where st.name = :name"); "where st.name = :name");
query.setParameter("name", name); query.setParameter("name", name);
return (AVMStore)query.uniqueResult(); AVMStore result = (AVMStore)query.uniqueResult();
synchronized (this)
{
if (result != null)
{
fNameCache.put(name, result.getId());
}
}
return result;
} }
/** /**
@@ -112,4 +137,12 @@ class AVMStoreDAOHibernate extends HibernateDaoSupport implements
{ {
return (AVMStore)getSession().get(AVMStoreImpl.class, id); return (AVMStore)getSession().get(AVMStoreImpl.class, id);
} }
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMStoreDAO#invalidateCache()
*/
public synchronized void invalidateCache()
{
fNameCache.clear();
}
} }