Esempio n. 1
0
    def test_cache_get_or_create(self):
        self.assertEqual(cache_get(self.vd1, 'name1'), None)
        value, is_created = cache_get_or_create(self.vd1, 'name1', None,
                                                lambda x: 'value%d' % x, 1)
        self.assertEqual(value, 'value1')
        self.assertEqual(is_created, True)
        value, is_created = cache_get_or_create(self.vd1, 'name1', None,
                                                lambda x: 'value%d' % x, 11)
        self.assertEqual(value, 'value1')
        self.assertEqual(is_created, False)
        cache_expire(self.vd1, 'name1', 1)
        sleep(1.001)
        value, is_created = cache_get_or_create(self.vd1, 'name1', None,
                                                lambda x: 'value%d' % x, 11)
        self.assertEqual(value, 'value11')
        self.assertEqual(is_created, True)

        cache_get_or_create(self.vd1, 'name2', None, lambda x: 'value%d' % x,
                            2)
        value, is_created = cache_get_or_create(self.vd1, 'name1', None,
                                                lambda x: 'value%d' % x, 11)
        self.assertEqual(value, 'value11')
        self.assertEqual(is_created, False)
        cache_get_or_create(self.vd2, 'name1', None, lambda x: 'asdf%d' % x, 1)
        value, is_created = cache_get_or_create(self.vd1, 'name1', None,
                                                lambda x: 'value%d' % x, 11)
        self.assertEqual(value, 'value11')
        self.assertEqual(is_created, False)
Esempio n. 2
0
    def test_cache_get_set(self):
        self.assertEqual(cache_get(self.vd1, 'name1'), None)
        self.assertEqual(cache_set(self.vd1, 'name1', None, lambda: 'value1'),
                         'value1')
        self.assertEqual(cache_get(self.vd1, 'name1'), 'value1')

        self.assertEqual(cache_set(self.vd1, 'name1', None, lambda: 'value11'),
                         'value1')
        self.assertEqual(cache_get(self.vd1, 'name1'), 'value1')
        cache_expire(self.vd1, 'name1', 1)
        sleep(1.001)
        self.assertEqual(cache_set(self.vd1, 'name1', None, lambda: 'value11'),
                         'value11')
        self.assertEqual(cache_get(self.vd1, 'name1'), 'value11')

        self.assertEqual(cache_get(self.vd1, 'name2'), None)
        self.assertEqual(cache_set(self.vd1, 'name2', None, lambda: 'value2'),
                         'value2')
        self.assertEqual(cache_get(self.vd1, 'name2'), 'value2')
        self.assertEqual(cache_get(self.vd1, 'name1'), 'value11')

        self.assertEqual(cache_get(self.vd2, 'name1'), None)
        self.assertEqual(cache_set(self.vd2, 'name1', None, lambda: 'asdf1'),
                         'asdf1')
        self.assertEqual(cache_get(self.vd2, 'name1'), 'asdf1')
        self.assertEqual(cache_get(self.vd2, 'name2'), None)
        self.assertEqual(cache_set(self.vd2, 'name2', None, lambda: 'asdf2'),
                         'asdf2')
        self.assertEqual(cache_get(self.vd2, 'name2'), 'asdf2')
        self.assertEqual(cache_get(self.vd1, 'name2'), 'value2')
        self.assertEqual(cache_get(self.vd1, 'name1'), 'value11')
Esempio n. 3
0
 def _clearCache(self):
     cache_expire(self.vd, self.post_cache_name)
     self._cache_userPost = None
     self._cache_total_pps = None
     self._cache_prev_tags = None
     self._cache_prev_NLL = None
     self._cache_vd_ids = None
     if self.place:
         self.place._clearCache()
Esempio n. 4
0
    def take(self, request, pk=None):
        # vd 조회
        vd = self.vd
        if not vd: return Response(status=status.HTTP_401_UNAUTHORIZED)

        iplace = self.get_object()
        pb = PostBase()
        pb.iplace_uuid = iplace.uuid
        pb.place_id = iplace.place_id
        pb.uplace_uuid = None

        uplace, is_created = UserPlace.get_or_create_smart(pb, vd)
        pp = PostPiece.create_smart(uplace, pb)
        serializer = UserPlaceSerializer(uplace)

        # for make taken place hidden
        from base.cache import cache_expire, cache_expire_ru
        cache_expire(vd, 'realOwner_place_ids')
        cache_expire_ru(vd, 'uplaces')
        return Response(serializer.data, status=status.HTTP_201_CREATED)
Esempio n. 5
0
 def _clearCache(self):
     cache_expire(None, 'placePost_%s' % self.id)
     self._cache_placePost = None