You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Mathias Nilsson <wi...@gmail.com> on 2010/09/25 17:00:12 UTC

Clear cached key Localizer

Hi,

I have copied the code from Localizer to support clearCachedKey. I want this
so that a user can change a text in the database and update the key. I don't
want to clear the entire cache because this will add roundtrips to the
database.

The getLocalizer() in component is final. Is there a better way of using the
clearCachedKey in a WebPage then 
((CacheUpdateableLocalizer) getLocalizer()).clearCachedKey("my.key",this);
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Clear-cached-key-Localizer-tp2713550p2713550.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Clear cached key Localizer

Posted by Mathias Nilsson <wi...@gmail.com>.
Added this to remove all keys regardless of the component

/**
	 * Remove every key from cache regardless of the component
	 * @param key the resource key
	 */
	public void clearCachedKeys(final String key){
		if( cache == null ) return;
		Iterator<Entry<String,String>> iter = cache.entrySet().iterator();
		while( iter.hasNext()){
			String[] splitKey = iter.next().getKey().split( "-" );
			if( splitKey[0].equals( key )){
				iter.remove();
			}
		}
	}
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Clear-cached-key-Localizer-tp2713550p2714650.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Clear cached key Localizer

Posted by Mathias Nilsson <wi...@gmail.com>.
Sorry,

This

public void clearCachedKey(final String key, final Component component){
		String cacheKey = getCacheKey(key, component);
		if( cacheKey != null ){
			if( cache.containsKey( cacheKey )){
				log.debug( "Removing key: " + cacheKey );
				cache.remove( cacheKey );
			}
		}
	}
	
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Clear-cached-key-Localizer-tp2713550p2713554.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Clear cached key Localizer

Posted by Mathias Nilsson <wi...@gmail.com>.
Just added these lines

public void clearCachedKey(final String key, final Component component,
final IModel<?> model){
		clearCachedKey(key, component, model, null);
	}
	public void clearCachedKey(final String key, final Component component){
		clearCachedKey(key, component, null, null);
	}
	public void clearCachedKey(final String key, final Component component,
final String defaultValue){
		clearCachedKey(key, component, null, defaultValue);
	}

	public void clearCachedKey(final String key, final Component component,
final IModel<?> model,final String defaultValue){
		String cacheKey = getCacheKey(key, component);
		if( cacheKey != null ){
			if( cache.containsKey( cacheKey )){
				log.debug( "Removing key: " + cacheKey );
				cache.remove( cacheKey );
			}
		}
	}
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Clear-cached-key-Localizer-tp2713550p2713552.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org