Cleaning up old Google Appenggine sessions


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. private void clearSessions() {
  2. DatastoreService datastore =
  3. DatastoreServiceFactory.getDatastoreService();
  4. Query query = new Query("_ah_SESSION");
  5. PreparedQuery results = datastore.prepare(query);
  6.  
  7. log.info("Deleting " + results.countEntities() + " sessions from
  8. data store");
  9.  
  10. for (Entity session : results.asIterable()) {
  11. datastore.delete(session.getKey());
  12. }
  13. }
  14.  
  15. // clearing everything in the cache, because sessions are also kept in
  16. memcache
  17.  
  18. private void clearCache() throws CacheException {
  19. CacheFactory cacheFactory = CacheManager.getInstance
  20. ().getCacheFactory();
  21. Cache cache = cacheFactory.createCache(Collections.emptyMap());
  22.  
  23. CacheStatistics stats = cache.getCacheStatistics();
  24. log.info("Clearing " + stats.getObjectCount() + " objects in
  25. cache");
  26.  
  27. cache.clear();
  28. }

URL: http://groups.google.com/group/google-appengine-java/browse_thread/thread/280c3fb95dac2314

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.