当前位置: 首页>>代码示例>>Python>>正文


Python MemcacheManager.set方法代码示例

本文整理汇总了Python中models.models.MemcacheManager.set方法的典型用法代码示例。如果您正苦于以下问题:Python MemcacheManager.set方法的具体用法?Python MemcacheManager.set怎么用?Python MemcacheManager.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.models.MemcacheManager的用法示例。


在下文中一共展示了MemcacheManager.set方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_page

# 需要导入模块: from models.models import MemcacheManager [as 别名]
# 或者: from models.models.MemcacheManager import set [as 别名]
 def get_page(cls, page_name, content_lambda):
   """Get page from cache or create page on demand."""
   content = MemcacheManager.get(page_name)
   if not content:
     logging.info('Cache miss: ' + page_name)
     content = content_lambda()
     MemcacheManager.set(page_name, content)
   return content
开发者ID:maxwillzq,项目名称:AllAboutPython,代码行数:10,代码来源:utils.py

示例2: get_announcements

# 需要导入模块: from models.models import MemcacheManager [as 别名]
# 或者: from models.models.MemcacheManager import set [as 别名]
    def get_announcements(cls, allow_cached=True):
        items = MemcacheManager.get(cls.memcache_key)
        if not allow_cached or items is None:
            items = AnnouncementEntity.all().order('-date').fetch(1000)

            # TODO(psimakov): prepare to exceed 1MB max item size
            # read more here: http://stackoverflow.com
            #   /questions/5081502/memcache-1-mb-limit-in-google-app-engine
            MemcacheManager.set(cls.memcache_key, items)
        return items
开发者ID:cglmoocs,项目名称:cgl-mooc-builder,代码行数:12,代码来源:announcements.py

示例3: get_forum_by_url

# 需要导入模块: from models.models import MemcacheManager [as 别名]
# 或者: from models.models.MemcacheManager import set [as 别名]
def get_forum_by_url(forumurl):
  # number of forums is small, so we cache all of them
  forums = memcache.get(FORUMS_MEMCACHE_KEY)
  if not forums:
    forums = Forum.all().fetch(200) # this effectively limits number of forums to 200
    if not forums:
      return None

    memcache.set(FORUMS_MEMCACHE_KEY, forums)
  for forum in forums:
    if forumurl == forum.url:
      return forum
  return None
开发者ID:twiffy,项目名称:eabooc,代码行数:15,代码来源:main.py

示例4: get_teacher_by_email

# 需要导入模块: from models.models import MemcacheManager [as 别名]
# 或者: from models.models.MemcacheManager import set [as 别名]
 def get_teacher_by_email(cls, email):
     """Returns enrolled teacher or None."""
     # ehiller - not sure if memcache check is in the right place, feel like we might want to do that after
     # checking datastore. this depends on what memcachemanager returns if a teacher hasn't been set there yet but
     #  still actually exists.
     teacher = MemcacheManager.get(cls._memcache_key(email))
     if NO_OBJECT == teacher:
         return None
     if not teacher:
         teacher = Teacher.get_by_email(email)
         if teacher:
             MemcacheManager.set(cls._memcache_key(email), teacher)
         else:
             MemcacheManager.set(cls._memcache_key(email), NO_OBJECT)
     if teacher:  # ehiller - removed isEnrolled check, don't think we still need a teacher to be
         # enrolled to get their data back
         return teacher
     else:
         return None
开发者ID:ehiller,项目名称:CourseBuilderTeacherDashboard,代码行数:21,代码来源:teacher_entity.py

示例5: get_activity_scores

# 需要导入模块: from models.models import MemcacheManager [as 别名]
# 或者: from models.models.MemcacheManager import set [as 别名]
    def get_activity_scores(cls, student_user_ids, course, force_refresh = True):
        """Retrieve activity data for student using EventEntity.

           For each student, launch a Query of EventEntities to retrieve student
           scores.  The Query is launched as a map-reduce background process that
           will return up to 500 results, reporting back every second.  It reports
           back by calling the map_fn callback, which in turn calls parse_activity
           scores.

           As soon as the Query is launched (in the background) the foreground
           process calls build_missing_scores() to construct a student_answer.dict
           that will be updated as score data for that student is received.

           Events properties include a userid (a number) and a source (e.g.,
           tag-assessement), a  recorded-on date (timestamp) and data (a dictionary).
           Here's a typeical data dict:

           {"loc": {"city": "mililani", "language": "en-US,en;q=0.8", "locale": "en_US",
           "country": "US", "region": "hi", "long": -158.01528099999999, "lat": 21.451331,
           "page_locale": "en_US"}, "instanceid": "yOkVTqWogdaF", "quid": "5733935958982656",
           "score": 1, "location": "https://mobilecsp-201608.appspot.com/mobilecsp/unit?unit=1&lesson=45",
           "answer": [0, 1, 2, 4], "type": "McQuestion", "user_agent":
            "Mozilla/5.0 ..."}

           Note that it includes the unit_id and lesson_id as part of the Url
        """

        # Instantiate parser object
        cached_date = datetime.datetime.now()
        activityParser = ActivityScoreParser()

        if force_refresh:
            activityParser.params = activityParser.build_additional_mapper_params(course.app_context)

            #  Launch a background Query for each student's activity data.  This is expensive.
            for user_id in student_user_ids:
#                if GLOBAL_DEBUG:
#                     logging.debug('***RAM*** launching a query for student ' + str(user_id))
                mapper = models_utils.QueryMapper(
                    EventEntity.all().filter('user_id in', [user_id])       \
                                     .filter('recorded_on  >= ', cls.CUTOFF_DATE), \
                                        batch_size=1000, report_every=1000)

                # Callback function -- e.g., 45-50 callbacks per query
                def map_fn(activity_attempt):
#                    if GLOBAL_DEBUG:
#                     logging.debug('***RAM*** map_fn ' + str(activity_attempt))
                    activityParser.parse_activity_scores(activity_attempt)

                mapper.run(map_fn)

            #  In the foreground create the student_answer_dict, which is stored at:
            #   activity_scores[student][unit][lesson][sequence]  where sequence is
            #   the question's sequential position within the lesson.
            #  So each question in the lesson will have a question_answer_dict.
            activityParser.build_missing_scores()

            #Lets cache results for each student
            for user_id in student_user_ids:
                cached_student_data = {}
                cached_student_data['date'] = cached_date

                student = Student.get_by_user_id(user_id)
                
                cached_student_data['scores'] = activityParser.activity_scores.get(student.email, {})
                cached_student_data['attempts'] = activityParser.num_attempts_dict.get(student.email, {})
                MemcacheManager.set(cls._memcache_key_for_student(student.email),cached_student_data)
        else:
            uncached_students = []
            for student_id in student_user_ids:
                if student_id != '':
                    student = Student.get_by_user_id(student_id)
                    temp_email = student.email
                    temp_mem = cls._memcache_key_for_student(temp_email)
                    scores_for_student = MemcacheManager.get(temp_mem)
                    if scores_for_student:
                        cached_date = scores_for_student['date']
                        activityParser.activity_scores[student_id] = scores_for_student['scores']
                        activityParser.num_attempts_dict[student_id] = scores_for_student['scores']
                    else:
                        uncached_students.append(student_id)
            if len(uncached_students) > 0:
                if cached_date == None or datetime.datetime.now() < cached_date:
                    cached_date = datetime.datetime.now()

                activityParser.params = activityParser.build_additional_mapper_params(course.app_context)

                for user_id in uncached_students:
                    mapper = models_utils.QueryMapper(
                        EventEntity.all().filter('user_id in', [user_id])       \
                                     .filter('recorded_on  >= ', cls.CUTOFF_DATE), \
                                        batch_size=1000, report_every=1000)

                    def map_fn(activity_attempt):
                        activityParser.parse_activity_scores(activity_attempt)

                    mapper.run(map_fn)

                activityParser.build_missing_scores()

#.........这里部分代码省略.........
开发者ID:ram8647,项目名称:gcb-mobilecsp,代码行数:103,代码来源:student_activites.py

示例6: get_activity_scores

# 需要导入模块: from models.models import MemcacheManager [as 别名]
# 或者: from models.models.MemcacheManager import set [as 别名]
    def get_activity_scores(cls, student_user_ids, course, force_refresh = False):
        """Retrieve activity data for student using EventEntity"""

        #instantiate parser object
        cached_date = datetime.datetime.now()
        activityParser = ActivityScoreParser()

        if force_refresh:
            activityParser.params = activityParser.build_additional_mapper_params(course.app_context)

            for user_id in student_user_ids:
                mapper = models_utils.QueryMapper(
                    EventEntity.all().filter('user_id in', [user_id]), batch_size=500, report_every=1000)

                def map_fn(activity_attempt):
                    activityParser.parse_activity_scores(activity_attempt)

                mapper.run(map_fn)

            activityParser.build_missing_scores()

            #Lets cache results for each student
            for user_id in student_user_ids:
                cached_student_data = {}
                cached_student_data['date'] = cached_date
                cached_student_data['scores'] = activityParser.activity_scores.get(Student.get_student_by_user_id(
                    user_id).email, {})
                MemcacheManager.set(cls._memcache_key_for_student(Student.get_student_by_user_id(user_id).email),
                                    cached_student_data)
        else:
            uncached_students = []
            for student_id in student_user_ids:
                scores_for_student = MemcacheManager.get(cls._memcache_key_for_student(Student.get_student_by_user_id(
                    student_id).email))
                if scores_for_student:
                    cached_date = scores_for_student['date']
                    activityParser.activity_scores[student_id] = scores_for_student['scores']
                else:
                    uncached_students.append(student_id)
            if len(uncached_students) > 0:
                if cached_date == None or datetime.datetime.now() < cached_date:
                    cached_date = datetime.datetime.now()

                activityParser.params = activityParser.build_additional_mapper_params(course.app_context)

                for user_id in uncached_students:
                    mapper = models_utils.QueryMapper(
                        EventEntity.all().filter('user_id in', [user_id]), batch_size=500, report_every=1000)

                    def map_fn(activity_attempt):
                        activityParser.parse_activity_scores(activity_attempt)

                    mapper.run(map_fn)

                activityParser.build_missing_scores()

                #Lets cache results for each student
                for user_id in uncached_students:
                    cached_student_data = {}
                    cached_student_data['date'] = cached_date
                    cached_student_data['scores'] = activityParser.activity_scores.get(Student.get_student_by_user_id(
                        user_id).email, {})
                    MemcacheManager.set(cls._memcache_key_for_student(Student.get_student_by_user_id(user_id).email),
                                        cached_student_data)

        score_data = {}
        score_data['date'] = cached_date
        score_data['scores'] = activityParser.activity_scores

        return score_data
开发者ID:ehiller,项目名称:CourseBuilderTeacherDashboard,代码行数:72,代码来源:teacher_parsers.py

示例7: put

# 需要导入模块: from models.models import MemcacheManager [as 别名]
# 或者: from models.models.MemcacheManager import set [as 别名]
 def put(self):
     """Do the normal put() and also add the object to memcache."""
     result = super(Teacher, self).put()
     MemcacheManager.set(self._memcache_key(self.key().name()), self)
     return result
开发者ID:ehiller,项目名称:CourseBuilderTeacherDashboard,代码行数:7,代码来源:teacher_entity.py

示例8: done

# 需要导入模块: from models.models import MemcacheManager [as 别名]
# 或者: from models.models.MemcacheManager import set [as 别名]
 def done(self):
     if self.new_keys_fetched:
         MemcacheManager.set(
                 self._collection_key,
                 list(str(x) for x in self.cache.keys()),
                 ttl=60*60*48)
开发者ID:twiffy,项目名称:eabooc,代码行数:8,代码来源:prefetch.py

示例9: set

# 需要导入模块: from models.models import MemcacheManager [as 别名]
# 或者: from models.models.MemcacheManager import set [as 别名]
 def set(self, *args, **kwargs):
     kwargs.setdefault('ttl', self.ttl)
     return MemcacheManager.set(*args, **kwargs)
开发者ID:twiffy,项目名称:eabooc,代码行数:5,代码来源:jinja_filters.py

示例10: get_sections

# 需要导入模块: from models.models import MemcacheManager [as 别名]
# 或者: from models.models.MemcacheManager import set [as 别名]
 def get_sections(cls, allow_cached=True):
     sections = MemcacheManager.get(cls.memcache_key)
     if not allow_cached or sections is None:
         sections = CourseSectionEntity.all().order('-date').fetch(1000)
         MemcacheManager.set(cls.memcache_key, sections)
     return sections
开发者ID:ram8647,项目名称:gcb-mobilecsp,代码行数:8,代码来源:course_entity.py


注:本文中的models.models.MemcacheManager.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。