@@ -42,14 +42,14 @@ def query_for_data():
4242
4343
4444def get_data (cache_key ):
45- ## data = memcache.get('key')
45+ ## data = memcache.get('key')
4646 data = client .get (cache_key )
4747
4848 if data is not None :
4949 return data .decode ()
5050 else :
5151 data = query_for_data ()
52- ## memcache.add('key', data, 60)
52+ ## memcache.add('key', data, 60)
5353 client .set (cache_key , data , ex = 60 )
5454
5555 return data
@@ -58,19 +58,19 @@ def get_data(cache_key):
5858def add_values (values , expires = 3600 ):
5959 # Add a value if it doesn't exist in the cache
6060 # with a cache expiration of 1 hour.
61- ## memcache.add(key="weather_USA_98105", value="raining", time=3600)
62- ## # Remove one of the values and set by itself first
63- ## first_key = values.keys()[0]
64- ## first_value = values[first_key]
65- ## del values[first_key]
66- ## memcache.add(first_key, first_value, ex=expires)
67- ##
68- ## # Set several values, overwriting any existing values for these keys.
69- ## memcache.set_multi(
70- ## {"USA_98115": "cloudy", "USA_94105": "foggy", "USA_94043": "sunny"},
71- ## key_prefix="weather_",
72- ## time=3600
73- ## )
61+ ## memcache.add(key="weather_USA_98105", value="raining", time=3600)
62+ ## # Remove one of the values and set by itself first
63+ ## first_key = values.keys()[0]
64+ ## first_value = values[first_key]
65+ ## del values[first_key]
66+ ## memcache.add(first_key, first_value, ex=expires)
67+ ##
68+ ## # Set several values, overwriting any existing values for these keys.
69+ ## memcache.set_multi(
70+ ## {"USA_98115": "cloudy", "USA_94105": "foggy", "USA_94043": "sunny"},
71+ ## key_prefix="weather_",
72+ ## time=3600
73+ ## )
7474 # Redis mset is similar to memcache.set_multi, but cannot set expirations
7575 client .mset (values )
7676
@@ -84,13 +84,13 @@ def add_values(values, expires=3600):
8484
8585def increment_counter (name , expires = 60 , value = 0 ):
8686 # Atomically increment an integer value.
87- ## memcache.set(key="counter", value=0)
87+ ## memcache.set(key="counter", value=0)
8888 client .set (name , value , ex = expires )
89- ## memcache.incr("counter")
89+ ## memcache.incr("counter")
9090 client .incr (name )
91- ## memcache.incr("counter")
91+ ## memcache.incr("counter")
9292 client .incr (name )
93- ## memcache.incr("counter")
93+ ## memcache.incr("counter")
9494 client .incr (name )
9595
9696
@@ -102,6 +102,7 @@ def increment_counter(name, expires=60, value=0):
102102def home ():
103103 return render_template ('index.html' )
104104
105+
105106@app .route ('/showdata' , methods = ['GET' ])
106107def showdata ():
107108 data = get_data ('data' )
@@ -114,6 +115,7 @@ def showdata():
114115
115116 return render_template ('showdata.html' , data = data , values = values )
116117
118+
117119@app .route ('/showdata' , methods = ['POST' ])
118120def savedata ():
119121 key = request .form ['key' ]
@@ -126,4 +128,4 @@ def savedata():
126128
127129if __name__ == '__main__' :
128130 # This is used when running locally.
129- app .run (host = '127.0.0.1' , port = 8080 , debug = True )
131+ app .run (host = '127.0.0.1' , port = 8080 , debug = True )
0 commit comments