清理旧的googleappengine会话

【清理旧的googleappengine会话】敢说敢作敢为, 无怨无恨无悔。这篇文章主要讲述清理旧的googleappengine会话相关的知识,希望能为你提供帮助。

  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. }


    推荐阅读