def init_counters(cls): super(VfsCacheConnection, cls).init_counters() cls.CACHE_NO_METADATA = PerfCounter( 'gcb-models-VfsCacheConnection-cache-no-metadata', 'A number of times an object was requested, but was not found and ' 'had no metadata.') cls.CACHE_INHERITED = PerfCounter( 'gcb-models-VfsCacheConnection-cache-inherited', 'A number of times an object was obtained from the inherited vfs.')
# 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. """Common classes and methods for managing persistent entities.""" __author__ = 'Pavel Simakov ([email protected])' from counters import PerfCounter import transforms from google.appengine.ext import db # datastore performance counters DB_QUERY = PerfCounter( 'gcb-models-db-query', 'A number of times a query()/all() was executed on a datastore.') DB_GET = PerfCounter( 'gcb-models-db-get', 'A number of times an object was fetched from datastore.') DB_PUT = PerfCounter( 'gcb-models-db-put', 'A number of times an object was put into datastore.') DB_DELETE = PerfCounter( 'gcb-models-db-delete', 'A number of times an object was deleted from datastore.') # String. Name of the safe key property used for data export. SAFE_KEY_NAME = 'safe_key'
# we cache this object below. NO_OBJECT = {} # The default amount of time to cache the items for in memcache. DEFAULT_CACHE_TTL_SECS = 60 * 5 # Global memcache controls. CAN_USE_MEMCACHE = ConfigProperty( 'gcb_can_use_memcache', bool, ('Whether or not to cache various objects in memcache. For production ' 'this value should be on to enable maximum performance. For ' 'development this value should be off so you can see your changes to ' 'course content instantaneously.'), appengine_config.PRODUCTION_MODE) # performance counters CACHE_PUT = PerfCounter('gcb-models-cache-put', 'A number of times an object was put into memcache.') CACHE_HIT = PerfCounter('gcb-models-cache-hit', 'A number of times an object was found in memcache.') CACHE_MISS = PerfCounter( 'gcb-models-cache-miss', 'A number of times an object was not found in memcache.') CACHE_DELETE = PerfCounter( 'gcb-models-cache-delete', 'A number of times an object was deleted from memcache.') class MemcacheManager(object): """Class that consolidates all memcache operations.""" @classmethod def get_namespace(cls): """Look up namespace from namespace_manager or use default."""
def __init__(self): self._cache = caching.LRUCache( max_size_bytes=MAX_GLOBAL_CACHE_SIZE_BYTES, max_item_size_bytes=MAX_GLOBAL_CACHE_ITEM_SIZE_BYTES) self._cache.get_entry_size = self._get_entry_size def _get_entry_size(self, key, value): return sys.getsizeof(key) + value.getsizeof() if value else 0 @property def cache(self): return self._cache VFS_CACHE_LEN = PerfCounter('gcb-models-VfsCacheConnection-cache-len', 'A total number of items in vfs cache.') VFS_CACHE_SIZE_BYTES = PerfCounter( 'gcb-models-VfsCacheConnection-cache-bytes', 'A total size of items in vfs cache in bytes.') VFS_CACHE_LEN.poll_value = ProcessScopedVfsCache.get_vfs_cache_len VFS_CACHE_SIZE_BYTES.poll_value = ProcessScopedVfsCache.get_vfs_cache_size class CacheFileEntry(caching.AbstractCacheEntry): """Cache entry representing a file.""" def __init__(self, filename, metadata, body): self.filename = filename self.metadata = metadata self.body = body self.created_on = datetime.datetime.utcnow()