|
From: Pelle B. <pe...@us...> - 2004-04-02 17:45:54
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2656/src/java/org/neuclear/id/cache Modified Files: NSCache.java Log Message: Added automatic caching of SignedNamedObject Index: NSCache.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/id/cache/NSCache.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** NSCache.java 3 Jan 2004 20:36:38 -0000 1.9 --- NSCache.java 2 Apr 2004 17:33:31 -0000 1.10 *************** *** 1,13 **** package org.neuclear.id.cache; - import org.neuclear.commons.NeuClearException; - import org.neuclear.id.Identity; - import org.neuclear.id.NSTools; import org.neuclear.id.SignedNamedObject; - import org.neuclear.id.InvalidNamedObjectException; - import java.util.Map; - import java.util.HashMap; import java.lang.ref.WeakReference; /** --- 1,9 ---- package org.neuclear.id.cache; import org.neuclear.id.SignedNamedObject; import java.lang.ref.WeakReference; + import java.util.HashMap; + import java.util.Map; /** *************** *** 23,27 **** - /** * Attempts to get a verified PublicKey for the given name from the cache --- 19,22 ---- *************** *** 32,50 **** public SignedNamedObject fetchCached(final String name) { final WeakReference ref = (WeakReference) spaces.get(name); ! if (ref==null) return null; return (SignedNamedObject) ref.get(); } ! public void cache(final SignedNamedObject ns) { ! // Only store if it's parent is already here ! try { ! final String parentName = NSTools.getSignatoryURI(ns.getName()); ! if ((fetchCached(parentName) != null) || (parentName.equals("neu://")||NSTools.isHttpScheme(ns.getName())!=null)) { ! spaces.put(ns.getName(),new WeakReference(ns)); ! } ! } catch (InvalidNamedObjectException e) { ! ;// If we have an issue here we will silently ignore it. ! } } --- 27,39 ---- public SignedNamedObject fetchCached(final String name) { final WeakReference ref = (WeakReference) spaces.get(name); ! if (ref == null) return null; return (SignedNamedObject) ref.get(); } ! public SignedNamedObject cache(final SignedNamedObject obj) { ! if (!spaces.containsKey(obj.getDigest())) ! spaces.put(obj.getDigest(), new WeakReference(obj)); ! return obj; } |