0
votes

I use java memcache api to store not persistent data associated with the user. Every user has associated memcache entity storing some properties, some of the properties are embedded entities. After a while they dissappear while other properties ( String, Integer, Boolean ) persist. Is it intended to be so or I am missing something in my code? Can I rely on entitites stored in cache at least for an hour or something like this? I see this behaviour when debugging on local machine with google plugin. My code is like this:

class UserData {
    public Entity getEntity() {
        Entity ret = new Entity( "User", key );
        ret.setProperty( "property1", _integerval );
        ret.setProperty( "property2", _stringval );
        ret.setProperty( "property3", _complex.getEmbEntity() );
        return ret;
    }

    public static UserData fromEntity( Entity ent ) {
        UserData ret = new UserData();
        ret._integerval = (Integer)ent.getProperty("property1");
        ret._stringval = (String)ent.getProperty("property2");
        ret._complex.fromEmbEntity( (EmbeddedEntity)ent.getProperty("property3") );
        return ret;
    }
}
1

1 Answers

3
votes

Remember google's implementation will not guarantee any entity will hang around. Anything can be evicted at any point. From the docs:

However, when considering whether to store a value solely in the memcache and not backed by other persistent storage, be sure that your application behaves acceptably when the value is suddenly not available. Values can expire from the memcache at any time, and may be expired prior to the expiration deadline set for the value.