Exemple #1
0
    def test_get_stored_metadata(self):
        from liquer.store import set_store, MemoryStore
        from liquer.cache import set_cache, MemoryCache, NoCache
        store = MemoryStore()
        store.store_metadata("a/b", dict(test="stored value 1"))
        set_store(store)

        cache = MemoryCache()
        cache.store_metadata(dict(query="c/d", test="stored value 2"))
        set_cache(cache)
        assert get_stored_metadata("-R/a/b")["test"] == "stored value 1"
        assert get_stored_metadata("a/b") is None  # this represents a query
        assert get_stored_metadata("c/d")["test"] == "stored value 2"

        set_store(None)
        set_cache(NoCache())
Exemple #2
0
    def test_cache_control(self):
        from liquer.cache import MemoryCache, set_cache, get_cache

        @command
        def cached(state):
            return state.with_caching(True).with_data(123)

        @command
        def cache_off(state):
            return state.with_caching(False).with_data(234)

        set_cache(MemoryCache())

        assert evaluate("cached").get() == 123
        assert evaluate("cache_off").get() == 234
        assert get_cache().contains("cached")
        assert not get_cache().contains("cache_off")
        set_cache(None)
        reset_command_registry()
Exemple #3
0
    def test_cache_control(self):
        from liquer.cache import MemoryCache, set_cache, get_cache

        @first_command
        def cached(context):
            context.enable_cache()
            return 123

        @command
        def cache_off(x, context):
            context.disable_cache()
            return 234

        set_cache(MemoryCache())

        assert evaluate("cached").get() == 123
        assert evaluate("cache_off").get() == 234
        assert get_cache().contains("cached")
        assert not get_cache().contains("cache_off")
        set_cache(None)
        reset_command_registry()
Exemple #4
0
import liquer.ext.lq_pandas
import pandas as pd

from liquer.cache import MemoryCache, FileCache, SQLCache, set_cache  # Setting cache

@first_command(my_cache="a")
def square(count=10):
    df = pd.DataFrame()
    for i in range(count):
        print("square", i)
        df = df.append(dict(x=i,y=i*i), ignore_index=True)
    return df

@first_command(my_cache="b")
def cube(count=10):
    df = pd.DataFrame()
    for i in range(count):
        print("cube", i)
        df = df.append(dict(x=i,y=i*i*i), ignore_index=True)
    return df

if __name__ == "__main__":
    set_cache(
        FileCache("cache_a").if_attribute_equal("my_cache","a") + 
        SQLCache.from_sqlite("cache_b.db").if_attribute_equal("my_cache","b") +
        MemoryCache() # Everything else 
    )
    evaluate_and_save("square/square.csv")
    evaluate_and_save("cube/cube.csv")
    evaluate_and_save("square/square.csv") # from cache a
    evaluate_and_save("cube/cube.csv") # from cache b
Exemple #5
0
from liquer import *
import pandas as pd
import numpy as np
import liquer.ext.basic
import liquer.ext.meta
import liquer.ext.lq_pandas  # Add pandas support to liquer so that the dataframe conversions work
from liquer.store import web_mount_folder
from liquer.cache import set_cache, MemoryCache

web_mount_folder("gui", "dist/liquer/web/gui")
### Create Flask app and register LiQuer blueprint
from flask import Flask
import liquer.server.blueprint as bp
app = Flask(__name__)

set_cache(MemoryCache())

url_prefix = '/liquer'
app.register_blueprint(bp.app, url_prefix=url_prefix)


@first_command(volatile=True)
def hello():
    return "Hello"


@app.route('/')
@app.route('/index.html')
def index():
    return """<h1>Hello-world app</h1>
    <ul>
Exemple #6
0
from liquer.cache import MemoryCache
from time import sleep


@first_command
def hello():
    sleep(0.5)
    return "Hello"


@command
def greet(greeting, who="world"):
    sleep(0.5)
    return f"{greeting}, {who}!"


if __name__ == "__main__":
    set_central_cache(
        MemoryCache()
    )  # without configuring cache, the evaluation will run in the main process

    #    evaluate_and_save("hello/greet/hello_greet.txt", target_directory=".")
    #    evaluate_and_save("hello/greet-everybody/hello_greet_everybody.txt", target_directory=".")

    evaluate_and_save_in_background("hello/greet/hello_greet.txt")
    evaluate_and_save_in_background(
        "hello/greet-everybody/hello_greet_everybody.txt")

    get_pool().close()
    get_pool().join()