Re: Improving the bean function with caching

2014-01-30 Thread pron
Here's the Javadoc . You can invalidate individual entries with the remove method. A class object itself - or at least those parts visible at runtime through reflection - can never change. Reloading a class with the same name (

Re: Improving the bean function with caching

2014-01-30 Thread pron
Sorry, you're right. No WeakReferences on the class keys, rather a map is stored in a field of Class (similarly to ThreadLocal). BTW, this ClassValue was written by John Rose as part of JSR 292, and a very interesting implementation vis-a-vis concurrency On Thursday, January 30, 2014 4:59:40 PM

Re: Improving the bean function with caching

2014-01-30 Thread Jozef Wagner
Well there is a remove method in ClassValue, http://docs.oracle.com/javase/7/docs/api/java/lang/ClassValue.html#remove(java.lang.Class)and it seems that the cache is implemented in a way that it does not hold class objects, thus it does not prevent class from GCing (the cached value is stored in cl

Re: Improving the bean function with caching

2014-01-30 Thread Ambrose Bonnaire-Sergeant
Is there any way to invalidate this cache? Thanks, Ambrose On Thu, Jan 30, 2014 at 9:35 PM, pron wrote: > The bean function is a very useful Java interop feature that provides a > read-only view of a Java Bean as a Clojure map. > As it stands, the function performs introspection on the bean's

Re: Improving the bean function with caching

2014-01-30 Thread Jozef Wagner
Sorry, I've misread your post. If you want this feature to be added to Clojure, please submit a ticket at http://dev.clojure.org/jira/browse/CLJ JW On Thu, Jan 30, 2014 at 3:16 PM, pron wrote: > I'm not caching the values, only the mapping from keywords to methods (the > caching is per class,

Re: Improving the bean function with caching

2014-01-30 Thread pron
I'm not caching the values, only the mapping from keywords to methods (the caching is per class, not per bean). It's just saving the introspection/reflection on each call. The values themselves are always obtained directly from the bean. On Thursday, January 30, 2014 4:12:31 PM UTC+2, Jozef Wag

Re: Improving the bean function with caching

2014-01-30 Thread Jozef Wagner
Hi, Not every bean is immutable, so you cannot cache its values by default. If reading from the bean is expensive for you, either create a normal hash-map with into {} and select-keys, or use memoize. user=> (def b (bean (java.util.Date.))) #'user/b user=> (def hm (into {} (select-keys b [:year :

Improving the bean function with caching

2014-01-30 Thread pron
The bean function is a very useful Java interop feature that provides a read-only view of a Java Bean as a Clojure map. As it stands, the function performs introspection on the bean's class whenever the function is called: (defn bean "Takes a Java object and returns a read-only implementation