當前位置: 首頁>>代碼示例>>Python>>正文


Python cache.Cache方法代碼示例

本文整理匯總了Python中flask.ext.cache.Cache方法的典型用法代碼示例。如果您正苦於以下問題:Python cache.Cache方法的具體用法?Python cache.Cache怎麽用?Python cache.Cache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask.ext.cache的用法示例。


在下文中一共展示了cache.Cache方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: plotwh

# 需要導入模塊: from flask.ext import cache [as 別名]
# 或者: from flask.ext.cache import Cache [as 別名]
def plotwh(hashstr,width,height):
    if len(hashstr) > 80: abort(500)
    global image_views 
    value_cache_clean_one()
    svg = file('main.svg','r').read()
    trdn = 20
    cd = CachedData.query.filter_by(phash=hashstr).first()
    if cd:
        try:
            max_val, valueMid, timeMid, secondsMid, neg_val, msg, points, y_shift, valueMin, l_y, nodata, avg_upd, late = generate_points(list(cd))
            cd.update()
            db.session.commit()
            if neg_val: trdn -= 68
            svg = apply_template(svg, {"MAXPOINTS":MAXPOINTS, "TRDN": trdn, "MSG":msg, "VALUEMID":valueMid, "TIMEMID":timeMid, "DATAPOINTS":points, "INIT_MAX_Y": max_val, "MAX_Y": max_val, "SECONDS_SCALE": secondsMid, "Y_SHIFT": y_shift, "ZERO": valueMin, "L_Y":l_y, "NODATA":nodata, "AVG_UPD": avg_upd, "LATE": late}) # TODO templating engine
        except:
            print "GENERATE_ERROR"
            traceback.print_exc()
            svg = apply_template(svg, {"MAXPOINTS":MAXPOINTS, "TRDN": trdn, "MSG":"", "VALUEMID":"0.5", "TIMEMID":"10s", "DATAPOINTS":"","INIT_MAX_Y": "false", "MAX_Y": 0, "SECONDS_SCALE":0, "Y_SHIFT": 0, "ZERO": 0, "L_Y":"", "NODATA":"", "AVG_UPD": 0, "LATE": "No data stream"}) # TODO templating engine
    else:
        svg = apply_template(svg, {"MAXPOINTS":MAXPOINTS, "TRDN": trdn, "MSG":"", "VALUEMID":"0.5", "TIMEMID":"10s", "DATAPOINTS":"","INIT_MAX_Y": "false", "MAX_Y": 0, "SECONDS_SCALE":0, "Y_SHIFT": 0, "ZERO": 0, "L_Y":"", "NODATA":"", "AVG_UPD": 0, "LATE": "No data stream"}) # TODO templating engine
        
    if width and height: svg = svg.replace('height="210" width="610"', 'height="%s" width="%s"' % (height, width)) # TODO: switch to templating
    image_views += 1
    return flask.Response(svg,  mimetype= 'image/svg+xml', headers={'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache'}) 
開發者ID:grandrew,項目名稱:plotti.co,代碼行數:26,代碼來源:evsvg.py

示例2: _create_blogging_engine

# 需要導入模塊: from flask.ext import cache [as 別名]
# 或者: from flask.ext.cache import Cache [as 別名]
def _create_blogging_engine(self):
        cache = Cache(self.app, config={"CACHE_TYPE": "simple"})
        return BloggingEngine(self.app, self.storage, cache=cache) 
開發者ID:ninadmhatre,項目名稱:zual,代碼行數:5,代碼來源:test_views.py

示例3: setUp

# 需要導入模塊: from flask.ext import cache [as 別名]
# 或者: from flask.ext.cache import Cache [as 別名]
def setUp(self):
        self.app = Flask(__name__)
        self.app.cache = Cache(self.app, config={'CACHE_TYPE': 'simple'})
        self.app.cache.clear()
        self.app_context = self.app.app_context()
        self.app_context.push() 
開發者ID:lyft,項目名稱:discovery,代碼行數:8,代碼來源:host_test.py

示例4: setUp

# 需要導入模塊: from flask.ext import cache [as 別名]
# 或者: from flask.ext.cache import Cache [as 別名]
def setUp(self):
        self.app = Flask(__name__)
        self.app.cache = Cache(self.app, config={'CACHE_TYPE': 'simple'})
        self.app.cache.clear()
        self.app_context = self.app.app_context()
        self.app_context.push()
        for item in Host.scan():
            item.delete() 
開發者ID:lyft,項目名稱:discovery,代碼行數:10,代碼來源:api_test.py

示例5: push_update

# 需要導入模塊: from flask.ext import cache [as 別名]
# 或者: from flask.ext.cache import Cache [as 別名]
def push_update(hashstr, data, cd=None):
    global updates_received 
    # TODO: split data cache?
    if not cd:
        cd = CachedData.query.filter_by(phash=hashstr).first()
    if not cd:
        cd = CachedData(hashstr)
        db.session.add(cd)
    
    cd.append((data, int(time.time())))
    cd.update()
    db.session.commit()
    if datastore: datastore.addData(hashstr, data)
    if not hashstr in subscriptions and not hashstr in tokenHashes: 
        # print "ERR: no subscribers, can not push", hashstr
        return ""
    
    def notify():
        global updates_pushed 
        updateHash = str(int(time.time()*1000))
        if hashstr in subscriptions: 
            updates_pushed += len(subscriptions[hashstr])
            for sub in subscriptions[hashstr][:]:
                sub.put("%s\t%s\t%s" % (hashstr, updateHash, data))
        if hashstr in tokenHashes:
            lClean = []
            for ptoken in tokenHashes[hashstr]:
                if not ptoken in tokenSubscriptions:
                    lClean.append(ptoken)
                    continue
                # TODO: clean up the tokenHashes by scheduled task
                updates_pushed += len(tokenSubscriptions[ptoken])
                for sub in tokenSubscriptions[ptoken][:]:
                    sub.put("%s\t%s\t%s" % (hashstr, updateHash, data))
            for ptoken in lClean:
                tokenHashes[hashstr].remove(ptoken)
                # print "Deleting ptoken",ptoken 
                if len(tokenHashes[hashstr]) == 0:
                    # print "Deleting tokanhash", hashstr
                    del tokenHashes[hashstr]
            
    gevent.spawn(notify)
    updates_received += 1
    return flask.Response('<svg xmlns="http://www.w3.org/2000/svg"></svg>', mimetype= 'image/svg+xml', headers={'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache'}) 
開發者ID:grandrew,項目名稱:plotti.co,代碼行數:46,代碼來源:evsvg.py

示例6: test_list

# 需要導入模塊: from flask.ext import cache [as 別名]
# 或者: from flask.ext.cache import Cache [as 別名]
def test_list(self, expired, query):
        self.app.cache = Cache(self.app, config={'CACHE_TYPE': 'null'})
        service = 'foo'
        query.return_value = []
        expired.return_value = False
        host = self._new_host_service()
        hosts = host.list(service)
        expected = []
        assert hosts == expected

        host1 = type('lamdbaobject', (object,), {})()
        host1.service = service
        host1.ip_address = '10.10.10.10'
        host1.service_repo_name = 'bar'
        host1.port = 80
        host1.revision = 'abc123'
        host1.last_check_in = datetime.utcnow()
        host1.tags = self._generate_valid_tags()
        host2 = type('lamdbaobject', (object,), {})()
        host2.service = service
        host2.ip_address = '10.10.10.11'
        host2.service_repo_name = 'bar'
        host2.port = 80
        host2.revision = 'abc123'
        host2.last_check_in = datetime.utcnow()
        host2.tags = self._generate_valid_tags()
        query.return_value = [
            host1,
            host2
        ]
        host = self._new_host_service()
        hosts = host.list(service)
        expected = [
            {
                'service': host1.service,
                'last_check_in': host1.last_check_in,
                'ip_address': host1.ip_address,
                'service_repo_name': host1.service_repo_name,
                'port': host1.port,
                'revision': host1.revision,
                'tags': host1.tags
            },
            {
                'service': host2.service,
                'last_check_in': host2.last_check_in,
                'ip_address': host2.ip_address,
                'service_repo_name': host2.service_repo_name,
                'port': host2.port,
                'revision': host2.revision,
                'tags': host2.tags
            }
        ]
        assert hosts == expected 
開發者ID:lyft,項目名稱:discovery,代碼行數:55,代碼來源:host_test.py

示例7: test_list_by_service_repo_name

# 需要導入模塊: from flask.ext import cache [as 別名]
# 或者: from flask.ext.cache import Cache [as 別名]
def test_list_by_service_repo_name(self, expired, query):
        self.app.cache = Cache(self.app, config={'CACHE_TYPE': 'null'})
        service = 'foo'
        service_repo_name = 'bar'
        query.return_value = []
        expired.return_value = False
        host = self._new_host_service()
        hosts = host.list_by_service_repo_name(service_repo_name)
        expected = []
        assert hosts == expected

        host1 = type('lamdbaobject', (object,), {})()
        host1.service = service
        host1.ip_address = '10.10.10.10'
        host1.service_repo_name = 'bar'
        host1.port = 80
        host1.revision = 'abc123'
        host1.last_check_in = datetime.utcnow()
        host1.tags = self._generate_valid_tags()
        host2 = type('lamdbaobject', (object,), {})()
        host2.service = service
        host2.ip_address = '10.10.10.11'
        host2.service_repo_name = 'bar'
        host2.port = 80
        host2.revision = 'abc123'
        host2.last_check_in = datetime.utcnow()
        host2.tags = self._generate_valid_tags()
        query.return_value = [
            host1,
            host2
        ]
        host = self._new_host_service()
        hosts = host.list_by_service_repo_name(service)
        expected = [
            {
                'service': host1.service,
                'last_check_in': host1.last_check_in,
                'ip_address': host1.ip_address,
                'service_repo_name': host1.service_repo_name,
                'port': host1.port,
                'revision': host1.revision,
                'tags': host1.tags
            },
            {
                'service': host2.service,
                'last_check_in': host2.last_check_in,
                'ip_address': host2.ip_address,
                'service_repo_name': host2.service_repo_name,
                'port': host2.port,
                'revision': host2.revision,
                'tags': host2.tags
            }
        ]
        assert hosts == expected 
開發者ID:lyft,項目名稱:discovery,代碼行數:56,代碼來源:host_test.py


注:本文中的flask.ext.cache.Cache方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。