Thank you very much.

On 01/08/2010 01:37 PM, Prashant Gupta wrote:
here is a small example :


@PersistenceCapable
public class Property implements Serializable{
@PrimaryKey
@Persistent
private String Key;
@Persistent(serialized = "true", defaultFetchGroup = "true")
private Object Value;
@Persistent
private Long Expiry;

private Property(String key, Object value, long expirationDeltaMillis){
this.Key = key;
this.Value = value;
if(expirationDeltaMillis > 0)
this.Expiry = new Date().getTime() + expirationDeltaMillis;
}
public static <T> T get(String key) {
Property property = WCMSHelper.getObjectById(Property.class, key);
if (property != null
&& (property.Expiry == null || property.Expiry >= new Date().getTime()))
return (T) property.Value;
else
return null;
}

public static void put(String key, Object value) {
Property.put(key, value, -1);
}
public static void put(String key, Object value,
long expirationDeltaMillis) {
Property property = new Property(key, value, expirationDeltaMillis);
/pmf/.makePersistent(property);
/cache/.put(property.Key, property);
}

}




2010/1/8 Prashant Gupta <[email protected] <mailto:[email protected]>>



    2010/1/8 Nicanor Cristian <[email protected]
    <mailto:[email protected]>>

        On 01/08/2010 10:58 AM, Prashant Gupta wrote:


        2010/1/8 nicanor.babula <[email protected]
        <mailto:[email protected]>>

            Hi everyone.

            How memcache works on GAE? Let me explain:
            Do I get one memcache instance per app instance or there
            is one
            memcache instance for all instastances of my app?

        one instance for all app instances.
        so if one app instance does:
        memcacheService.put("loggedUser", userData1);

        and later another app instance does:
        (UserData) memcacheService.get("loggedUser");
        The latter instance will get the same data that the first
        instance put?

    yeah.


            My app uses google accounts to handle users. I am
            thinking that it
            might be faster reading the current user data from the
            memcache
            instead of calling userService.getCurrentUser(). It would
            be a good
            approach?

        no! memcache data is not persistent, your memcache data could
        be removed any time for any reason, like limited memory,
        cache age, etc. I suggest you to go through docs.
        I don't want to use it for persistence. I use the datastore
        for persistence.
        Once a user logs in I want to write to the memcache the logged
        user data in order to read it later (during one login session).

    yes you can do this but memcache doesn't guarantee to keep the
    data for you when you come back to see it. so, you must use a
    persistent storage i.e. datasore,  to make sure that you will get
    your data back next time. what you can do is to save your data to
    datastore and memcache both, next time if you do not find your
    data in memcache you can get it from datastore and save it to
    memcache again for next time !

            Thanks,
            Cristian.

            --
            You received this message because you are subscribed to
            the Google Groups "Google App Engine for Java" group.
            To post to this group, send email to
            [email protected]
            <mailto:[email protected]>.
            To unsubscribe from this group, send email to
            [email protected]
            <mailto:google-appengine-java%[email protected]>.
            For more options, visit this group at
            http://groups.google.com/group/google-appengine-java?hl=en.






-- You received this message because you are subscribed to the
        Google Groups "Google App Engine for Java" group.
        To post to this group, send email to
        [email protected]
        <mailto:[email protected]>.
        To unsubscribe from this group, send email to
        [email protected]
        <mailto:[email protected]>.
        For more options, visit this group at
        http://groups.google.com/group/google-appengine-java?hl=en.


-- You received this message because you are subscribed to the
        Google Groups "Google App Engine for Java" group.
        To post to this group, send email to
        [email protected]
        <mailto:[email protected]>.
        To unsubscribe from this group, send email to
        [email protected]
        <mailto:google-appengine-java%[email protected]>.
        For more options, visit this group at
        http://groups.google.com/group/google-appengine-java?hl=en.





--
You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.

--
You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to