dkunzler / esperandro

Easy SharedPreference Engine foR ANDROid
Other
180 stars 14 forks source link

Public function to reset all cached values #41

Closed MFlisar closed 8 years ago

MFlisar commented 8 years ago

Please add a public reset cache function. When using your library with preference fragments, I will have to invalidate any cached values, because preference fragments don't allow to pass in a SharedPreference object, but only a preference name... Currently I use reflection like following for it:

    PrefManager$$Impl prefs = (PrefManager$$Impl) MainApp.getPrefs();
    try
    {
        Field field = PrefManager$$Impl.class.getDeclaredField("cache");
        field.setAccessible(true);
        Object cache = field.get(prefs);
        Method evictAll = cache.getClass().getDeclaredMethod("evictAll", new Class[]{});
        evictAll.invoke(cache);
    }
    catch (NoSuchFieldException e)
    {
        e.printStackTrace();
    } 
    catch (IllegalAccessException e)
    {
        e.printStackTrace();
    } 
    catch (NoSuchMethodException e)
    {
        e.printStackTrace();
    } 
    catch (InvocationTargetException e)
    {
        e.printStackTrace();
    }