com.openexchange.mail.cache
Class MailMessageCache

java.lang.Object
  extended by com.openexchange.mail.cache.MailMessageCache

public final class MailMessageCache
extends java.lang.Object

MailMessageCache - Caches instances of MailMessage which are prepared for caching by invoking MailPart.prepareForCaching(); meaning to release all kept content references. Thus only message's header data is going to be cached.

This cache is highly volatile. With every new list request all caches entries belonging to requesting user are removed. See this cache region's configuration settings in file "@conf-path@/mailcache.ccf" for further information.

Author:
Thorben Betten

Method Summary
 boolean containsFolderMessages(int accountId, java.lang.String fullname, int userId, int cid)
          Detects if cache holds messages belonging to a certain folder.
 boolean containsUserMessages(int userId, int cid)
          Detects if cache holds messages belonging to given user.
static MailMessageCache getInstance()
          Gets the singleton instance.
 MailMessage[] getMessages(java.lang.String[] uids, int accountId, java.lang.String fullname, int userId, int cid)
          Gets the corresponding messages from cache.
 void initCache()
          Initializes cache reference.
 void putMessages(int accountId, MailMessage[] mails, int userId, int cid)
          Puts given messages into cache.
 void releaseCache()
          Releases cache reference.
static void releaseInstance()
          Releases the singleton instance.
 void removeFolderMessages(int accountId, java.lang.String fullname, int userId, int cid)
          Removes cached messages belonging to a certain folder.
 void removeMessages(java.lang.String[] uids, int accountId, java.lang.String fullname, int userId, int cid)
          Removes the messages appearing in given UIDs belonging to a certain folder.
 void removeUserMessages(int userId, int cid)
          Removes the messages cached for a user.
 void updateCachedMessages(int accountId, java.lang.String fullname, int userId, int cid, MailListField[] changedFields, java.lang.Object[] newValues)
          Updates cached message
 void updateCachedMessages(java.lang.String[] uids, int accountId, java.lang.String fullname, int userId, int cid, MailListField[] changedFields, java.lang.Object[] newValues)
          Updates cached message
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initCache

public void initCache()
               throws com.openexchange.cache.OXCachingException
Initializes cache reference.

Throws:
com.openexchange.cache.OXCachingException - If initializing the cache reference fails

releaseCache

public void releaseCache()
                  throws com.openexchange.cache.OXCachingException
Releases cache reference.

Throws:
com.openexchange.cache.OXCachingException - If clearing cache fails

getInstance

public static MailMessageCache getInstance()
                                    throws com.openexchange.cache.OXCachingException
Gets the singleton instance.

Returns:
The singleton instance
Throws:
com.openexchange.cache.OXCachingException - If instance initialization failed

releaseInstance

public static void releaseInstance()
Releases the singleton instance.


updateCachedMessages

public void updateCachedMessages(java.lang.String[] uids,
                                 int accountId,
                                 java.lang.String fullname,
                                 int userId,
                                 int cid,
                                 MailListField[] changedFields,
                                 java.lang.Object[] newValues)
Updates cached message

Parameters:
uids - The messages' identifiers; pass null update all cached message of given folder
accountId - The account ID
fullname - The fullname
userId - The user identifier
cid - The context identifier
changedFields - The changed fields
newValues - The new values

updateCachedMessages

public void updateCachedMessages(int accountId,
                                 java.lang.String fullname,
                                 int userId,
                                 int cid,
                                 MailListField[] changedFields,
                                 java.lang.Object[] newValues)
Updates cached message

Parameters:
accountId - The account ID
fullname - The fullname
userId - The user identifier
cid - The context identifier
changedFields - The changed fields
newValues - The new values

containsUserMessages

public boolean containsUserMessages(int userId,
                                    int cid)
Detects if cache holds messages belonging to given user.

Parameters:
userId - The user ID
cid - The context ID
Returns:
true if messages are present; otherwise false

containsFolderMessages

public boolean containsFolderMessages(int accountId,
                                      java.lang.String fullname,
                                      int userId,
                                      int cid)
Detects if cache holds messages belonging to a certain folder.

Parameters:
accountId - The account ID
fullname - The folder fullname
userId - The user ID
cid - The context ID
Returns:
true if cache holds messages belonging to a certain folder; otherwise false

removeUserMessages

public void removeUserMessages(int userId,
                               int cid)
                        throws com.openexchange.cache.OXCachingException
Removes the messages cached for a user.

Parameters:
userId - The user ID
cid - The context ID
Throws:
com.openexchange.cache.OXCachingException

removeFolderMessages

public void removeFolderMessages(int accountId,
                                 java.lang.String fullname,
                                 int userId,
                                 int cid)
Removes cached messages belonging to a certain folder.

Parameters:
accountId - The account ID
fullname - The folder fullname
userId - The user ID
cid - The context ID

removeMessages

public void removeMessages(java.lang.String[] uids,
                           int accountId,
                           java.lang.String fullname,
                           int userId,
                           int cid)
Removes the messages appearing in given UIDs belonging to a certain folder.

Parameters:
uids - The mail IDs; pass null to remove all associated with folder
accountId - The account ID
fullname - The folder fullname
userId - The user ID
cid - The context ID

getMessages

public MailMessage[] getMessages(java.lang.String[] uids,
                                 int accountId,
                                 java.lang.String fullname,
                                 int userId,
                                 int cid)
Gets the corresponding messages from cache. If a cache entry could not be found null is returned to force a reload from mail server.

Parameters:
uids - The UIDs
accountId - The account ID
fullname - The folder fullname
userId - The user ID
cid - The context ID
Returns:
An array of MailMessage containing the fetched messages or null

putMessages

public void putMessages(int accountId,
                        MailMessage[] mails,
                        int userId,
                        int cid)
                 throws com.openexchange.cache.OXCachingException
Puts given messages into cache.

Parameters:
accountId - The account ID
mails - The messages to cache
userId - The user ID
cid - The context ID
Throws:
com.openexchange.cache.OXCachingException - If cache put fails