Пример #1
0
 def test_keyof_api(self):
     key_1 = wrapcache.keyof(self.test_class.test_input_cache, i = 1, j = 'hello world')
     key_2 = wrapcache.keyof(self.test_class.test_input_cache, i = 1, j = 'hello world')
     key_3 = wrapcache.keyof(self.test_class.test_input_cache, j = 'hello world', i = 1)
     key_4 = wrapcache.keyof(self.test_class.test_input_cache, j = 'hello wrapcache', i = 1)
     self.assertEqual(key_1, key_2, 'test_keyof_api fail')
     self.assertEqual(key_1, key_3, 'test_keyof_api fail')
     self.assertNotEqual(key_1, key_4, 'test_keyof_api fail')
Пример #2
0
 def test_keyof_api(self):
     key_1 = wrapcache.keyof(self.test_class.test_input_cache, i=1, j="hello world")
     key_2 = wrapcache.keyof(self.test_class.test_input_cache, i=1, j="hello world")
     key_3 = wrapcache.keyof(self.test_class.test_input_cache, j="hello world", i=1)
     key_4 = wrapcache.keyof(self.test_class.test_input_cache, j="hello wrapcache", i=1)
     self.assertEqual(key_1, key_2, "test_keyof_api fail")
     self.assertEqual(key_1, key_3, "test_keyof_api fail")
     self.assertNotEqual(key_1, key_4, "test_keyof_api fail")
Пример #3
0
 def test_keyof_api(self):
     key_1 = wrapcache.keyof(self.test_class.test_input_cache, i = 1, j = 'hello world')
     key_2 = wrapcache.keyof(self.test_class.test_input_cache, i = 1, j = 'hello world')
     
     key_3 = wrapcache.keyof(self.test_class.test_input_cache, j = 'hello world', i = 1)
     key_4 = wrapcache.keyof(self.test_class.test_input_cache, j = 'hello wrapcache', i = 1)
     self.assertEqual(key_1, key_2, 'test_keyof_api fail')
     self.assertEqual(key_1, key_3, 'test_keyof_api fail')
     self.assertNotEqual(key_1, key_4, 'test_keyof_api fail')
Пример #4
0
    def test_apis(self):
        wrapcache.flush()
        # get api
        key_1 = wrapcache.keyof(self.test_class.test_input_cache, i=1, j="hello world")
        value_1 = wrapcache.get(key_1)
        self.assertEqual(value_1, None, "test_apis fail")
        # set api
        value_2 = wrapcache.set(key_1, "test_value", timeout=3)
        self.assertEqual(value_2, "test_value", "test_keyof_api fail")
        # get api / timeout
        value_3 = wrapcache.get(key_1)
        self.assertEqual(value_3, "test_value", "test_keyof_api fail")
        time.sleep(3)
        self.assertEqual(wrapcache.get(key_1), None, "test_apis fail")

        # remove api
        value_4 = wrapcache.set(key_1, "test_value 4", timeout=3)
        self.assertEqual(value_4, "test_value 4", "test_keyof_api fail")
        value_5 = wrapcache.remove(key_1)
        self.assertEqual(value_4, value_5, "test_keyof_api fail")
        self.assertEqual(wrapcache.get(key_1), None, "test_apis fail")

        # flush api
        value_6 = wrapcache.set(key_1, "test_value 4", timeout=3)
        self.assertEqual(value_6, "test_value 4", "test_keyof_api fail")
        self.assertTrue(wrapcache.flush(), "test_keyof_api fail")
        self.assertEqual(wrapcache.get(key_1), None, "test_apis fail")
Пример #5
0
    def test_apis(self):
        wrapcache.flush()
        #get api
        key_1 = wrapcache.keyof(self.test_class.test_input_cache,
                                i=1,
                                j='hello world')
        value_1 = wrapcache.get(key_1)
        self.assertEqual(value_1, None, 'test_apis fail')
        #set api
        value_2 = wrapcache.set(key_1, 'test_value', timeout=3)
        self.assertEqual(value_2, 'test_value', 'test_keyof_api fail')
        #get api / timeout
        value_3 = wrapcache.get(key_1)
        self.assertEqual(value_3, 'test_value', 'test_keyof_api fail')
        time.sleep(3)
        self.assertEqual(wrapcache.get(key_1), None, 'test_apis fail')

        #remove api
        value_4 = wrapcache.set(key_1, 'test_value 4', timeout=3)
        self.assertEqual(value_4, 'test_value 4', 'test_keyof_api fail')
        value_5 = wrapcache.remove(key_1)
        self.assertEqual(value_4, value_5, 'test_keyof_api fail')
        self.assertEqual(wrapcache.get(key_1), None, 'test_apis fail')

        #flush api
        value_6 = wrapcache.set(key_1, 'test_value 4', timeout=3)
        self.assertEqual(value_6, 'test_value 4', 'test_keyof_api fail')
        self.assertTrue(wrapcache.flush(), 'test_keyof_api fail')
        self.assertEqual(wrapcache.get(key_1), None, 'test_apis fail')
Пример #6
0
    def test_apis(self):
        wrapcache.flush()
        #get api
        key_1 = wrapcache.keyof(self.test_class.test_input_cache, i = 1, j = 'hello world')
        value_1 = wrapcache.get(key_1)
        if not value_1:
            keyNone = True
        self.assertEqual(keyNone, True, 'test_apis fail')
        #set api
        value_2 =  wrapcache.set(key_1, 'test_value', timeout = 3)
        self.assertEqual(value_2, 'test_value', 'test_keyof_api fail')
        #get api / timeout
        value_3 = wrapcache.get(key_1)
        self.assertEqual(value_3, 'test_value', 'test_keyof_api fail')
        time.sleep(3)
        value_3 = wrapcache.get(key_1)
        if not value_3:
            keyNone = True
        self.assertEqual(keyNone, True, 'test_apis fail')

        #remove api
        value_4 =  wrapcache.set(key_1, 'test_value 4', timeout = 3)
        self.assertEqual(value_4, 'test_value 4', 'test_keyof_api fail')
        value_5 = wrapcache.remove(key_1)
        self.assertEqual(value_4, value_5, 'test_keyof_api fail')

        value_3 = wrapcache.get(key_1)
        if not value_5:
            keyNone = True
        self.assertEqual(keyNone, True, 'test_apis fail')

        #flush api
        value_6 =  wrapcache.set(key_1, 'test_value 4', timeout = 3)
        self.assertEqual(value_6, 'test_value 4', 'test_keyof_api fail')
        self.assertTrue(wrapcache.flush(), 'test_keyof_api fail')

        value_6 = wrapcache.get(key_1)
        if not value_6:
            keyNone = True
        self.assertEqual(keyNone, True, 'test_apis fail')
Пример #7
0
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import wrapcache
from time import sleep
import random


@wrapcache.wrapcache(timeout=3)
def need_cache_function(input, t=2, o=3):
    sleep(2)
    return random.randint(1, 100)


if __name__ == "__main__":
    for i in range(10):
        # sleep(1)
        print(need_cache_function(1, t=2, o=3))

    # get cache Programmatic
    key_func = wrapcache.keyof(need_cache_function)
    print(wrapcache.get(key_func))

    # remove cache Programmatic
    # print(wrapcache.remove(wrapcache.keyof(need_cache_function, 1, o=3, t=2)))