History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CACHE-149
Type: New Feature New Feature
Status: Open Open
Priority: Major Major
Assignee: Andres March
Reporter: moshe malaver
Votes: 12
Watchers: 15
Operations

If you were logged in you would be able to see more operations.
OSCache

get all values API is missing

Created: 08/Mar/05 01:31 AM   Updated: 14/Jun/07 09:49 AM
Component/s: Base Classes
Affects Version/s: 2.1
Fix Version/s: 3.0

File Attachments: 1. Java Source File Cache.java (44 kb)
2. Java Source File GeneralCacheAdministrator.java (14 kb)
3. Java Source File NeedsRefreshException.java (2 kb)

Environment: I am using the oscache is a weblogic application server

Flags: Patch


 Description  « Hide
I need to get from the cache all of its values, but currently this functionality
is missing.
in my opinion, it should be added. (needs to add a method in Cache.class and a proxy method in AbstractCacheAdministrator.class )

 All   Comments   Change History      Sort Order:
Alex Atran - [11/Jul/05 07:50 AM ]
I think another method to get All values by group would be useful as well.

Pasquale Marcoccia - [14/Jun/07 09:49 AM ]
I worked on 2.4 version...

In Cache class I implemented a method permits to retrieve all objects that belong to a specified group and it was been necessary add attribute "key" to NeedsRefreshException exception (more details below).

    /**
     * Retrieve all objects that belong to the supplied group.
     *
     * @param group The group to retrieve.
     * @param refreshPeriod How long before each object belongs to group needs refresh.
     * To allow the object to stay in the cache indefinitely, supply
     * a value of {@link CacheEntry#INDEFINITE_EXPIRY}.
     * @param cronExpiry A cron expression that specifies fixed date(s)
     * and/or time(s) that each entry belongs to group should
     * expire on.
     *
     * @return A list of objects from cache that belong to group.
     *
     * @throws NeedsRefreshException Thrown when one of the objects is stale.
     * When this exception occurs, the CacheEntry corresponding to the supplied
     * key will be locked and other threads requesting this entry will potentially
     * be blocked until the caller repopulates the cache. If the caller choses not
     * to repopulate the cache, they <em>must</em> instead call {@link #cancelUpdate(String)}.
     *
     * @note [CACHE-149]
     */
    public List getGroupFromCache(String group, int refreshPeriod, String cronExpiry) throws NeedsRefreshException {
        // get group entries
        Set groupEntries = cacheMap.getGroup(group);
        
        if (groupEntries == null){
            return null;
        }
        
        List entryList = new ArrayList(groupEntries.size());
        Iterator itr = groupEntries.iterator();
        String key;

        while (itr.hasNext()) {
            key = (String) itr.next();
            entryList.add( getFromCache(key, refreshPeriod, cronExpiry) );
        }

        return entryList;
    }

Here is an example with failover. Tipically we have a method for retrieve an object cached:

public Object getFromCache(String key){
    Object obj;
    try {
        // Get from the cache
        obj = admin.getFromCache(key);
    } catch (NeedsRefreshException nre) {
        try {
           // Get the value (probably by calling an EJB)
           obj = new Object();
           // Store in the cache
           admin.putInCache(key, obj);
           updated = true;
       } finally {
           if (!updated) {
               // It is essential that cancelUpdate is called if the
               // cached content could not be rebuilt
               admin.cancelUpdate(myKey);
           }
       }
   }
}

And here is the method to retrieve objects belong to a specified group:

public List getGroupFromCache(String group) {
        boolean isOk = false;
        List objList = null;
        String oldKey = null;
        while (!isOk){
            try {
                objList = cacheAdmin.getGroupFromCache(group);
                isOk = true;
            } catch (NeedsRefreshException ex) {
                final String key = ex.getKey();
                if (key.equals(oldKey)){
                    throw ex; // probably an application exception
                }
                oldKey = key;
                getFromCache(, true);
            }
        }
        return objList;
    }
}

The "key" from NeedsRefreshException helps to figure out which object key needs refresh. To avoid loops whenever NeedsRefreshException, i retrieve object only one time.

I have attached the modified classes to this comment.

Pasquale Marcoccia