You can call the factory any times it doesn't matter it will return you the
same cache.

Thanks,
Rahul
----------------------------------------------------------
Rahul Juneja
http://techlabs.thoughtclicks.com


2010/5/26 Viðar Svansson <[email protected]>

> I am curious, does it matter if I call the factory each time I need an
> instance of MemcacheService? I am trying to keep the startup time to
> minimum so it would be good to know. Currently I create a global
> instance on startup which may or may not be used by the request.
>
> Cheers,
> Viðar
>
> On Wed, May 26, 2010 at 3:15 AM, Rahul <[email protected]> wrote:
> > A Quick update, I tried this with low level google api and that seems
> > to work perfectly fine and i am able to retrieve values from the
> > existing cache and don't load it from db everytime hence reduces my
> > jvm restart load time by 3-4 seconds.
> >
> > Not sure what jsr 107 was not working.
> >
> > Thanks,
> > Rahul
> >
> >
> > On May 25, 10:24 pm, Rahul <[email protected]> wrote:
> >> Ikai,
> >>
> >> I am guessing i am wrong somewhere in designing this cache solution.
> >> Would appreciate if you can tell me where am i going wrong on this.
> >> Let me try to explain it once again.
> >>
> >> I have a set of properties which i load on first call to the service.
> >> and the code I call in the service is as follows.
> >>
> >> PropertiesCache _cache = PropertiesCache.getInstance();
> >>
> >> My PropertiesCache is as follows.
> >> -------------------------------------------------------------------
> >> public class PropertiesCache {
> >>         private static final Logger log =
> >> Logger.getLogger(PropertiesCache.class.getName());
> >>
> >>         private static PropertiesCache _instance;
> >>         private Cache cache;
> >>         private PropertiesCache() {
> >>                 try {
> >>                         log.info("In the PropertiesCache constructor");
> >>                         cache =
> >>
> CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
> >>                         //Loading the cache from the database.
> >>                         //cache.put(Object, Object);
> >>                 } catch (CacheException e) {
> >>                         log.severe("Error in creating the Loading
> Cache");
> >>                 }
> >>
> >>         public static synchronized PropertiesCache getInstance() {
> >>                 if (_instance == null) {
> >>                         _instance = new PropertiesCache();
> >>                 }else{
> >>                         log.info("Using existing cache instance and NO
> NEW Instance is
> >> created");
> >>                 }
> >>
> >>                 return _instance;
> >>         }
> >>
> >> Also, Let me re-iterate what you said, you are suggesting me not to
> >> play around with instance variable instead use the cache variable and
> >> is there any way i can fetch the cache variable once the jvm restarts.
> >>
> >> Appreciate all the efforts.
> >>
> >> Thanks,
> >> Rahul
> >> On May 25, 5:08 pm, "Ikai L (Google)" <[email protected]> wrote:
> >>
> >> > The instance itself will be recreated. If you store a value into
> Memcache,
> >> > it will likely be there the next time you retrieve it. Try this out.
> >>
> >> > It's not necessary to do what you've done here. When you create a
> Cache
> >> > instance, you're really just creating a client to the cache, and you
> can do
> >> > this each time you need it. There's no need to create a global,
> long-lived
> >> > instance. What you're seeing is perfectly normal - Java objects will
> not
> >> > have a longer lifespan than the JVM. If the JVM dies, so will all the
> >> > instantiated objects.
> >>
> >> > On Tue, May 25, 2010 at 1:28 PM, Rahul <[email protected]>
> wrote:
> >> > > Toby,
> >>
> >> > > I also had the same opinion but as you can see the previous code i
> >> > > have given populates the cache again. I guess i am doing something
> >> > > wrong. Appreciate if you can look at that and let me know if i have
> to
> >> > > do something which i missing.
> >>
> >> > > Thanks,
> >> > > Rahul
> >>
> >> > > On May 25, 4:00 pm, Toby Reyelts <[email protected]> wrote:
> >> > > > Rahul,
> >>
> >> > > > If you're using App Engine's MemcacheService directly (or
> indirectly, for
> >> > > > example through our JSR 107 support), then you are talking to
> backend
> >> > > > memcache instances that have lifetimes separate from your JVMs.
> >>
> >> > > > I.E. MemcacheServiceFactory.getMemcacheService<
> >> > >
> http://code.google.com/appengine/docs/java/javadoc/com/google/appengi...()
> >>
> >> > > > does
> >> > > > not create a new memcache backend - it just "connects" to an
> existing
> >> > > one.
> >> > > > You have one logical memcache backend that is shared between all
> of your
> >> > > > application's JVMs.
> >>
> >> > > > On Tue, May 25, 2010 at 3:12 PM, Rahul <[email protected]>
> wrote:
> >> > > > > Ikai,
> >>
> >> > > > > I am not sure what you mean by Memcache instances stays up
> because i
> >> > > > > tried the following code and everytime when a new jvm instance
> is
> >> > > > > created, the cache instance is also created again. Below is the
> code i
> >> > > > > am using, let me know if i am missing anything or not doing
> anything
> >> > > > > correct.
> >>
> >> > > > > Request comes from the following code:
> >>
> >> > > > > MyCache _cache = MyCache.getInstance();
> >> > > > > redirectUrl = _cache.findInCache(requestedURI);
> >>
> >> > > > > MyCache Class:
> >>
> >> > > > >        private static MyCache _instance;
> >> > > > >        private Cache cache;
> >>
> >> > > > >        public static synchronized MyCache getInstance() {
> >> > > > >                if (_instance == null) {
> >> > > > >                        _instance = new MyCache();
> >> > > > >                }else{
> >> > > > >                        log.info("Using existing cache instance
> and NO
> >> > > NEW
> >> > > > > Instance is
> >> > > > > created");
> >> > > > >                }
> >>
> >> > > > >                return _instance;
> >> > > > >        }
> >>
> >> > > > > and in the constructor i am creating new cache fetching
> everything
> >> > > > > from the database.
> >>
> >> > > > > Also, i have a listener in place which tells me when the new jvm
> >> > > > > instance is started.
> >>
> >> > > > > Thanks,
> >> > > > > Rahul
> >>
> >> > > > > On May 24, 3:56 pm, "Ikai L (Google)" <[email protected]>
> wrote:
> >> > > > > > Memcache instances stay up. They're shared, namespaced
> (security)
> >> > > > > instances
> >> > > > > > and will more likely than not outlive the lifecycles of your
> >> > > application
> >> > > > > > instances.
> >>
> >> > > > > > On Sun, May 23, 2010 at 11:17 PM, Tristan <
> >> > > [email protected]
> >> > > > > >wrote:
> >>
> >> > > > > > > Does anyone know the answer to this:
> >>
> >> > > > > > > If all the JVMs are killed, does the memcache stick around
> or is it
> >> > > > > > > recycled? (I know memcache expires eventually, just curious
> if it
> >> > > is
> >> > > > > > > possible for it to carry data across JVM valley of death)
> >>
> >> > > > > > > Cheers,
> >>
> >> > > > > > > Tristan
> >>
> >> > > > > > > --
> >> > > > > > > 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]<google-appengine-java%[email protected]>
> <google-appengine-java%[email protected]<google-appengine-java%[email protected]>
> ><google-appengine-java%2B
> >> > > [email protected]><google-appengine-java%2B
> >> > > > > [email protected]>
> >> > > > > > > .
> >> > > > > > > For more options, visit this group at
> >> > > > > > >http://groups.google.com/group/google-appengine-java?hl=en.
> >>
> >> > > > > > --
> >> > > > > > Ikai Lan
> >> > > > > > Developer Relations, Google App Engine
> >> > > > > > Twitter:http://twitter.com/ikai
> >> > > > > > Delicious:http://delicious.com/ikailan
> >>
> >> > > > > > ----------------
> >> > > > > > Google App Engine links:
> >> > > > > > Blog:http://googleappengine.blogspot.com
> >> > > > > > Twitter:http://twitter.com/app_engine
> >> > > > > > Reddit:http://www.reddit.com/r/appengine
> >>
> >> > > > > > --
> >> > > > > > 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]<google-appengine-java%[email protected]>
> <google-appengine-java%[email protected]<google-appengine-java%[email protected]>
> ><google-appengine-java%2B
> >> > > [email protected]>
> >> > > > > .
> >> > > > > > For more options, visit this group athttp://
> >> > > > > 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]<google-appengine-java%[email protected]>
> <google-appengine-java%[email protected]<google-appengine-java%[email protected]>
> ><google-appengine-java%2B
> >> > > [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]<google-appengine-java%[email protected]>
> <google-appengine-java%[email protected]<google-appengine-java%[email protected]>
> >
> >> > > .
> >> > > For more options, visit this group at
> >> > >http://groups.google.com/group/google-appengine-java?hl=en.
> >>
> >> > --
> >> > Ikai Lan
> >> > Developer Programs Engineer, Google App Engine
> >> > Twitter:http://twitter.com/ikai
> >> > Delicious:http://delicious.com/ikailan
> >>
> >> > ----------------
> >> > Google App Engine links:
> >> > Blog:http://googleappengine.blogspot.com
> >> > Twitter:http://twitter.com/app_engine
> >> > Reddit:http://www.reddit.com/r/appengine
> >>
> >>
> >
> > --
> > 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]<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]<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.

Reply via email to