当前位置: 首页>>代码示例>>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;未经允许,请勿转载。