[ 
https://issues.apache.org/jira/browse/OLINGO-124?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13874458#comment-13874458
 ] 

Michael Bolz edited comment on OLINGO-124 at 1/17/14 5:45 AM:
--------------------------------------------------------------

Hi Miki,

at your sample you have to define the {{List<Schema>}} or the {{ODataService}} 
as {{static}} fields.
{code} 
  private static List<Schema> schemas = new ArrayList<Schema>(); 
{code} 

and 

{code} 
  private static ODataService theODataService = null; 
{code} 

Best practice for only caching metadata generation would be to define only the 
{{EdmProvider}} as {{static}}.
Then in your {{EdmProvider}} implementation you can use your code example from 
above.

Below is a sample in which therefore the [Initialization on demand holder idiom 
is used|http://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom].

{code}
  private static class EdmProviderHolder {
    private static final EdmProvider INSTANCE = new ScenarioEdmProvider();
  }
  
  @Override
  public ODataService createService(final ODataContext context) throws 
ODataException {
    DataContainer dataContainer = new DataContainer();

    return createODataSingleProcessorService(
        EdmProviderHolder.INSTANCE,
        new ListsProcessor(new ScenarioDataSource(dataContainer)));
  }
{code}

Can you please try it and give feedback whether this solution fit for your use 
case.
I would then use this issue as first _question_ for an _FAQ_ in our wiki  ;o)

Kind regards,
Michael


was (Author: mirbo):
Hi Miki,

at your sample you have to define the {{List<Schema>}} or the {{ODataService}} 
as {{static}} fields.
{code} 
  private static List<Schema> schemas = new ArrayList<Schema>(); 
{code} 

and 

{code} 
  private static ODataService theODataService = null; 
{code} 

Best practice for only caching metadata generation would be to define only the 
{{EdmProvider}} as {{static}}.
Below is a sample in which therefore the [Initialization on demand holder idiom 
is used|http://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom].

{code}
  private static class EdmProviderHolder {
    private static final EdmProvider INSTANCE = new ScenarioEdmProvider();
  }
  
  @Override
  public ODataService createService(final ODataContext context) throws 
ODataException {
    DataContainer dataContainer = new DataContainer();

    return createODataSingleProcessorService(
        EdmProviderHolder.INSTANCE,
        new ListsProcessor(new ScenarioDataSource(dataContainer)));
  }
{code}

Can you please try it and give feedback whether this solution fit for your use 
case.
I would then use this issue as first _question_ for an _FAQ_ in our wiki  ;o)

Kind regards,
Michael

> Caching of metadata document
> ----------------------------
>
>                 Key: OLINGO-124
>                 URL: https://issues.apache.org/jira/browse/OLINGO-124
>             Project: Olingo
>          Issue Type: Question
>          Components: odata2-core
>    Affects Versions: V2 1.0.0
>            Reporter: M Carissimi
>            Assignee: Michael Bolz
>            Priority: Minor
>
> We generate the metadata at runtime using custom database queries and in 
> odata4j we can cache the metadata document to avoid having to rebuild it 
> every time a request is received. How can metadata be cached between requests 
> in olingo? Following the simple read example on the olingo website, we use an 
> ODataServiceFactory to create a service using method 
> createODataSingleProcessorService(), but these methods are invoked during 
> each request. 
> Hello Michael,
> the only remaining question I have is about caching of the schemas. I have 
> already attempted to cache the schema list in my custom EdmProvider in the 
> getSchemas() method, but this has had no effect.
> {code}
>   private List<Schema> schemas = new ArrayList<Schema>();
>   ...
>   public List<Schema> getSchemas() throws ODataException
>   {
>     if (schemas.size() == 0)
>     {
>     Schema schema = new Schema();
>     ...
>     schemas.add(schema);
>     }
>     return schemas;
>   }
> {code}
> Running the code in debugging mode, I can see that method createService() of 
> the service factory class configured as initi-parameter of the 
> CXFNonSpringJaxrsServlet servlet is invoked during each invocation and this 
> forces the creation of a new EdmProvider class on each invocation
> {code}
>   private ODataService theODataService = null;
>   ...
>   @Override
>   public ODataService createService(ODataContext ctx) throws ODataException
>   {
>     if (theODataService == null)
>     {
>       EdmProvider edmProvider = new ResourceNoLinksProvider();
>       ODataSingleProcessor singleProcessor = new ResourceSingleProcessor();
>       theODataService = createODataSingleProcessorService(edmProvider, 
> singleProcessor);
>     }
>     return theODataService;
>   }
> {code}
> Do you have any other suggestion about caching the schemas or metadata? In 
> odata4j, we were able to cache the metadata represented by EdmDataServices 
> using a similar approach to the one above. The main difference is that the 
> factory class was invoked by Jesey rather than CXF.
> Regards
> Miki



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to