Added missing files

This commit is contained in:
Jedrzej Nowak 2015-12-03 11:07:09 +01:00
parent 07f827104e
commit 07fba211bf
3 changed files with 35 additions and 14 deletions

View File

@ -1,9 +1,20 @@
from heapq import nsmallest
# Copyright 2015 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from collections import Counter
from operator import itemgetter
from collections import defaultdict, Counter
from solar.dblayer.proxy import DBLayerProxy
import gc
import sys
from threading import RLock
@ -25,8 +36,10 @@ class LFUCache(object):
store_len = len(self._store)
if store_len >= self._maxsize:
deleted = 0
exp_deleted = (store_len - self._maxsize) + 1 # overflow + one more
for k, _ in sorted(self._use_count.iteritems(), key=itemgetter(1)):
# overflow + one more
exp_deleted = (store_len - self._maxsize) + 1
for k, _ in sorted(self._use_count.iteritems(),
key=itemgetter(1)):
if self.is_deletable(self._store[k]):
del self[k]
deleted += 1
@ -46,7 +59,7 @@ class LFUCache(object):
def __eq__(self, other):
if isinstance(other, dict):
for k, v in other.iteritems():
if not k in self._store:
if k not in self._store:
return False
mv = self._store[k]
if not v == mv:

View File

@ -86,16 +86,9 @@ class SingleIndexCache(object):
class SingleClassCache(object):
<<<<<<< HEAD:solar/dblayer/model.py
__slots__ = ['obj_cache', 'db_ch_state', 'lazy_save', 'origin_class']
=======
__slots__ = ['obj_cache', 'db_ch_state',
'lazy_save', 'origin_class',
'refs']
<<<<<<< HEAD
>>>>>>> 3f53526... Initial idea of new cache:solar/solar/dblayer/model.py
=======
>>>>>>> f8f2630... Pretify code
def __init__(self, origin_class):
self.obj_cache = LFUCache(origin_class, 200)

View File

@ -1,3 +1,18 @@
# Copyright 2015 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import wrapt