Exemplo n.º 1
0
import fake_database

from memcache import Memcache

CACHE = Memcache()


def printname():
    return str(__name__)


def updateLastMultiplied(a,b,result):
    key = "lastFive"
    lastFiveList = CACHE.get(key)
    if lastFiveList:
        if len(lastFiveList) >= 5:
            newList = lastFiveList[1:]
            newList.append("{} X {} = {}".format(a,b,result))
            done = CACHE.set(key, newList)
        else:
            lastFiveList.append("{} X {} = {}".format(a,b,result))
            done = CACHE.set(key, lastFiveList)
    else:
        done = CACHE.set(key, ["{} X {} = {}".format(a,b,result)])


def lastMultipliedHandler():
    """
    Inputs : none
    Outputs : The last 5 multiplied result
    """
Exemplo n.º 2
0
from memcache import Memcache

cache = Memcache()
cache.set('a', 10)
cache.set('b', 10)
assert cache.count(10) == 2
assert cache.count(20) == 0
cache.delete('a')
assert cache.count(10) == 1
cache.set('b', 30)
assert cache.count(10) == 0

cache = Memcache()
cache.begin()
cache.set('a',10)
assert cache.get('a') == 10
cache.begin()
cache.set('a',20)
assert cache.get('a') == 20
cache.rollback()
assert cache.get('a') == 10
cache.rollback()
assert cache.get('a') == 'NULL'

cache = Memcache()
cache.begin()
cache.set('a',30)
cache.begin()
cache.set('a',40)
cache.commit()
assert cache.get('a') == 40
Exemplo n.º 3
0
#!/usr/bin/env python3

import fake_database
from memcache import Memcache

cache = Memcache()


def printName():
    return str(__name__)


def updateLastMultiplied(a, b, result):
    key = 'lastFive'
    lastFiveList = cache.get(key)
    if lastFiveList:
        if len(lastFiveList) >= 5:
            # The list already had five items in it
            newList = lastFiveList[1:]
            newList.append('{}x{}={}'.format(a, b, result))
            done = cache.set(key, newList)
        else:
            #The list had less than five items
            lastFiveList.append('{}x{}={}'.format(a, b, result))
            done = cache.set(key, lastFiveList)

    else:
        # There was not a cache so create one

        done = cache.set(key, ['{}x{}={}'.format(a, b, result)])
Exemplo n.º 4
0
import fake_database

from memcache import Memcache 

CACHE = Memcache()

def printName():
	return str(__name__)

def updateLastMultiplied(a, b, result):
	key = 'lastFive'
	lastFiveList = CACHE.get(key)
	if lastFiveList:
		if len(lastFiveList) >= 5:
			##The list already have five itms in it
			newList = lastFiveList[1:]
			newList.append('{}x{}={}'.format(a,b,result))
			done = CACHE.set(key, newList)
		else:
		## The list had less than five items
			lastFiveList.append('{}x{}={}'.format(a,b,result))
			done = CACHE.set(key, lastFiveList)
	else:
		## The was nota a Cache so create one
		done = CACHE.set(key, ['{}x{}={}'.format(a,b,result)]) 
	#return "Last 5:", CACHE.get(key)			
    
def lastMultipliedHandler():
	key = 'lastFive'
	last = CACHE.get(key)
	if last: