<commit_before>#    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 inspect
import networkx
import uuid

from solar import errors
from solar.core import validation
from solar.interfaces.db import base
from solar.interfaces.db import get_db

import os

# USE_CACHE could be set only from CLI
USE_CACHE = int(os.getenv("USE_CACHE", 0))


db = get_db()


from functools import wraps

def _delete_from(store):
    def _wrp(key):
        try:
            del store[key]
        except KeyError:
            pass
    return _wrp

def cache_me(store):
    def _inner(f):
        # attaching to functions even when no cache enabled for consistency
        f._cache_store = store
        f._cache_del = _delete_from(store)
        @wraps(f)
        def _inner2(obj, *args, **kwargs):
            try:
                return store[obj.id]
            except KeyError:
                pass
            val = f(obj, *args, **kwargs)
            if not val:
                return
            store[obj.id] = val<commit_msg>Fixed naive cache behaviour for location_id and transports<commit_after>#    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 inspect
import networkx
import uuid

from solar import errors
from solar.core import validation
from solar.interfaces.db import base
from solar.interfaces.db import get_db

import os

# USE_CACHE could be set only from CLI
USE_CACHE = int(os.getenv("USE_CACHE", 0))


db = get_db()


from functools import wraps

def _delete_from(store):
    def _wrp(key):
        try:
            del store[key]
        except KeyError:
            pass
    return _wrp

def cache_me(store):
    def _inner(f):
        # attaching to functions even when no cache enabled for consistency
        f._cache_store = store
        f._cache_del = _delete_from(store)
        @wraps(f)
        def _inner2(obj, *args, **kwargs):
            try:
                return store[obj.id]
            except KeyError:
                pass
            val = f(obj, *args, **kwargs)
            if obj.id.startswith('location_id'):
                if not val.value:
                    return val
            if obj.id.startswith('transports_id'):
                if not val.value:
                    return val
            if not val:
                return val
            store[obj.id] = val
{'fraction_non_alphanumeric': 0.07057451151939341, 'fraction_numerical': 0.0058326042578011085, 'mean_word_length': 2.2760267430754535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6248846', 'n_tokens_mistral': 960, 'n_tokens_neox': 934, 'n_words': 369}