当前位置: 首页>>代码示例>>Python>>正文


Python Cache.delete方法代码示例

本文整理汇总了Python中cache.Cache.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.delete方法的具体用法?Python Cache.delete怎么用?Python Cache.delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cache.Cache的用法示例。


在下文中一共展示了Cache.delete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete

# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import delete [as 别名]
def delete(url):
    """Delete <url> from cache"""
    url = urllib.unquote(url)
    if url.endswith("/"):
        raise Error("illegal url - can't delete a directory")

    print "* del: removing file from cache..."
    cache = Cache()
    result = cache.delete(url)

    return result
开发者ID:vinodpanicker,项目名称:ccurl,代码行数:13,代码来源:ccurl.py

示例2: Database

# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import delete [as 别名]
class Database(object):
    def __init__(self, multi_value=False, cache_port=None, router=None, domain=None):
        self._db = CommonDB(name=self.name, router=router, domain=domain)
        self._multi_value = multi_value
        if cache_port != None:
            self._cache = Cache(cache_port)
        else:
            self._cache = None

    @property
    def name(self):
        return self.__class__.__name__.lower()

    def get(self, key, first=False):
        val = None
        cache = False
        if self._cache:
            cache = True
            if not self._multi_value or first:
                val = self._cache.get(key)

        if not val:
            coll = self._db.collection(key)
            conn = self._db.connection(coll)
            val = self._db.get(conn, key)

            if self._multi_value:
                if first and type(val) == list:
                    val = val[0]
                else:
                    cache = False

            if cache:
                self._cache.put(key, val)
        return val

    def put(self, key, value):
        if self._cache:
            self._cache.delete(key)
        if not self._multi_value:
            val = {'$set':{VAL_NAME:value}}
        else:
            val = {'$addToSet':{VAL_NAME:value}}
        coll = self._db.collection(key)
        conn = self._db.connection(coll)
        self._db.put(conn, key, val, create=True)

    def delete(self, key, value=None, regex=False):
        if self._cache:
            self._cache.delete(key)

        coll = self._db.collection(key)
        conn = self._db.connection(coll)
        if not value:
            self._db.delete(conn, key)
        else:
            if not self._multi_value:
                log_err(self, 'failed to delete')
                raise Exception(log_get(self, 'failed to delete'))
            if not regex:
                self._db.put(conn, key, {'$pull':{VAL_NAME:value}})
            else:
                self._db.put(conn, key, {'$pull':{VAL_NAME:{'$regex':value}}})
开发者ID:virtdev,项目名称:virtdev,代码行数:65,代码来源:database.py

示例3: DataManager

# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import delete [as 别名]

#.........这里部分代码省略.........
            attribute, operator, value = filter
            field = self.table.fields.find_attribute(attribute)
            if operator.upper()=='LIKE':
                wheres.append('upper(' + field_name + ') LIKE ' + field.attr_to_field(value.upper() + '%'))
            else:
                wheres.append(field.field_name + operator + field.attr_to_field(value))
        where = ' WHERE ' + string.join(wheres, ' AND ')
        return self.table.select + where

    def get_all(self):
        """
        Returns a set of all objects managed by this data manager.

        If the data manager's cache proves sufficient to cache all objects,
        the cache will subsequently be considered preloaded, i.e.,
        subsequent calls to get_by_keys() will be served directly from the
        cache, bypassing expensive database accesses. See the preload()
        function for more information on preloading.
        """
        if self.cache.filled==1:
            self.all_cached = 0
        if self.all_cached==0:
            #print 'Loading all of ' + self.table.name + ' into cache.'
            set = self.get_sql(self.table.select)
            if self.cache.filled==0:
                self.all_cached = 1
            return set
        return self.get_cached()

    def synch(self):
        """
        Synchronize objects in the object cache with the database.

        Objects which have been deleted in the database are removed
        from the object cache.
        
        Objects which are out of synch with their database record
        have their attribute set to match the data in the database.
        """
        #print 'Synchronizing ' + self.table.name + ' with database'
        last_synched = self.last_synched        # Remember this, because we're about to overwrite it.
        self.last_synched = now_string()

        # Delete any newly deleted objects.
        sql = 'SELECT identifier FROM deleted WHERE table_name=' + wsq(self.table.name) + ' AND deleted >= ' + wsq(last_synched)
        cursor = db.select(sql)
        while (1):
            row = cursor.fetchone()
            if row==None: break
            
            # Load keys for the deleted object
            object = self.new_object()
            if len(self.table.key_list)==1:
                field = self.table.fields[self.table.key_list[0]]
                value = field.field_to_attr(row[0])
                setattr(object, field.attribute, value)
            else:
                values = row[0].split()
                for key in self.table.key_list:
                    field = self.table.fields[key]
                    value = field.field_to_attr(values[field.index])
                    setattr(object, field.attribute, value)
            object.key = self.table.get_key(object)

            #print 'Deleting from ' + self.table.name + ' cache: ' + str(value)
            self.cache.delete(object)
开发者ID:Fat-Zer,项目名称:LDP,代码行数:70,代码来源:base.py


注:本文中的cache.Cache.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。