thanks Paolo and Leonel,

things seems even weirder than I had in mind:

1. changing the order of the decorators: the program doesn't work anymore, there's no csv response anymore
2. the code form Leonel works, as long as you use it as a plain example

Now I made 2 identical csv services, both with a cache decorator (code below).
The first one is called as a procedure in a controller

*  response.baapje = service_platdak2()**
*
and the other one is used a csv file for the javascript DyGraph in the viewer

*<script type="text/javascript">**
**  graph2 = new Dygraph(**
**    document.getElementById ( "pygraph2" ),**
**    "../call/csv/service_platdak",**
**    {**
*
The call in the controller is perfectly well cached,
the javascript call is not cached.

To be sure that the code was the same, I exchanged the name in the controler call and viewer call
*
  response.baapje = service_platdak()**
*
and the other one is used a csv file for the javascript DyGraph in the viewer

*<script type="text/javascript">**
**  graph2 = new Dygraph(**
**    document.getElementById ( "pygraph2" ),**
**    "../call/csv/service_platdak2",**
**    {**
*
with exactly the same result:
The call in the controller is perfectly well cached,
the javascript call is not cached.

Any ideas ?

The complete code of the service:
#************************************************************
#************************************************************
try:
  sys.test_platdak
except :
  sys.test_platdak = 1

@cache('service_platdak', 300, cache.ram )
@service.csv
def service_platdak():
  ToDay     = date.today()
  Tomorrow  = ( ToDay + timedelta (1) )
  Yesterday = ( ToDay - timedelta (1) )

  # **********************************
  # Get Solar Power current day
  # **********************************
  SQL = """
select Date, M2, M2_s1
  from Compare_Model
  where Date >= ?
    and Date <  ?
    and M2_s1 > 0
  order by Date
"""
  Current = db.executesql ( SQL, ( ToDay, Tomorrow ) )

  # **********************************
  # Get total result of yesterday
  # **********************************
  SQL = """
select total(M2), total(M2_s1)
  from Compare_Model
  where Date >= ?
    and Date <  ?
    and M2_s1 > 0
"""
  Gisteren = db.executesql ( SQL, ( Yesterday, ToDay ) )
  Sum    = Molenhoek_2.WattPeak * float ( Gisteren[0][0] ) / 6000
  SumM   = Molenhoek_2.WattPeak * float ( Gisteren[0][1] ) / 6000

  # **********************************
  # build the result
  # **********************************
  Rows = []
Rows.append ('Date,Power[Watt],Energy[kWh],Model[Watt],Model[kWh]'.split(','))

  # **********************************
  # add previous day sum to first and second row
  # **********************************
  Row    = [ 0, 0, Sum, 0, SumM ]
  Row[0] = Current[0][0] - timedelta ( hours = 1 )
  Row[1] = sys.test_platdak
  sys.test_platdak += 1
  Rows.append ( Row )

  Row = copy ( Row )
  Row[0] =  Current[0][0]
  Rows.append ( Row )

  # **********************************
  # add all measurements of today
  # **********************************
  Sum  = 0
  SumM = 0
  for Row in Current :
    Power = 0
    PowerM = 0
    if not Row[1] is None :
      Power = Molenhoek_2.WattPeak * float ( Row[1] )
      Sum  += Power
    if not Row[2] is None :
      PowerM = Molenhoek_2.WattPeak * float ( Row[2] )
      SumM  += PowerM
    New = [ Row[0], Power, Sum/6000, PowerM, SumM/6000 ]
    Rows.append ( New )

  return Rows




On 11-Jan-15 16:55, Leonel Câmara wrote:
There must be something else wrong with your code. This should work. My test:


@cache('test', 600, cache.ram )
@service.csv
def test():
    import sys
    try:
       sys.N_Schuurdak += 1
    except :
       sys.N_Schuurdak = 10
    return {'N_Schuurdak': sys.N_Schuurdak}


As expected it returned 10 for 10 minutes and then 11.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to